conn_get_header: Fix bug

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
main
Jianhui Zhao 2020-07-02 23:31:25 +08:00
parent 97ab9877a2
commit e9666e82e2
1 changed files with 2 additions and 1 deletions

View File

@ -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;