From e9666e82e27dd2103ff6513e7c4125e9f2ebf089 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Thu, 2 Jul 2020 23:31:25 +0800 Subject: [PATCH] conn_get_header: Fix bug Signed-off-by: Jianhui Zhao --- src/connection.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/connection.c b/src/connection.c index c1cfa63..3038d14 100644 --- a/src/connection.c +++ b/src/connection.c @@ -202,6 +202,7 @@ static const char *conn_get_query(struct uh_connection *conn) static const char *conn_get_header(struct uh_connection *conn, const char *name) { struct uh_request *req = &conn->req; + int name_len = strlen(name); int i, j; for (i = 0; i < UHTTPD_MAX_HEADER_NUM; i++) { @@ -217,7 +218,7 @@ static const char *conn_get_header(struct uh_connection *conn, const char *name) for (j = 0; j < UHTTPD_MAX_HEADER_NUM; j++) { if (req->headers_info[j].name_offset > 0) { const char *p = O2D(conn, req->headers_info[j].name_offset); - if (!strncmp(p, name, req->headers_info[j].name_len)) { + if (name_len == req->headers_info[j].name_len && !strncmp(p, name, req->headers_info[j].name_len)) { req->headers[i].name = strndup(p, req->headers_info[j].name_len); req->headers[i].value = strndup(O2D(conn, req->headers_info[j].value_offset), req->headers_info[j].value_len); req->headers_info[j].name_len = 0;