HTTP parser: fixed parsing of field values ending with space.

This closes #82 issue on GitHub.
This commit is contained in:
Valentin Bartenev
2018-03-15 20:52:39 +03:00
parent f81fa2a921
commit 5a003df1fe
2 changed files with 16 additions and 8 deletions

View File

@@ -606,7 +606,7 @@ static nxt_int_t
nxt_http_parse_field_value(nxt_http_request_parse_t *rp, u_char **pos,
u_char *end)
{
u_char *p, ch;
u_char *p, *start, ch;
size_t len;
p = *pos;
@@ -625,14 +625,16 @@ nxt_http_parse_field_value(nxt_http_request_parse_t *rp, u_char **pos,
p++;
}
*pos = p;
start = p;
p += rp->field_value.length;
p = nxt_http_lookup_field_end(p, end);
if (nxt_slow_path(p == end)) {
len = p - *pos;
*pos = start;
len = p - start;
if (nxt_slow_path(len > NXT_HTTP_MAX_FIELD_VALUE)) {
return NXT_HTTP_PARSE_TOO_LARGE_FIELD;
@@ -649,22 +651,22 @@ nxt_http_parse_field_value(nxt_http_request_parse_t *rp, u_char **pos,
return NXT_HTTP_PARSE_INVALID;
}
if (nxt_fast_path(p != *pos)) {
*pos = p;
if (nxt_fast_path(p != start)) {
while (p[-1] == ' ') {
p--;
}
}
len = p - *pos;
len = p - start;
if (nxt_slow_path(len > NXT_HTTP_MAX_FIELD_VALUE)) {
return NXT_HTTP_PARSE_TOO_LARGE_FIELD;
}
rp->field_value.length = len;
rp->field_value.start = *pos;
*pos = p;
rp->field_value.start = start;
return nxt_http_parse_field_end(rp, pos, end);
}

View File

@@ -226,6 +226,12 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = {
NXT_DONE,
NULL, { NULL }
},
{
nxt_string("GET / HTTP/1.1\r\n"
"Host:example.com \r\n\r\n"),
NXT_DONE,
NULL, { NULL }
},
{
nxt_string("GET / HTTP/1.1\r\n"
"Host:\r\n\r\n"),