summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2018-03-15 20:52:39 +0300
committerValentin Bartenev <vbart@nginx.com>2018-03-15 20:52:39 +0300
commit5a003df1fedc45ba091e947a9d7b7f2351d6edb6 (patch)
tree80e7bbb8b07fbf2067636beeb9b0616a86ca825a
parentf81fa2a921c56a8dba42b39dd65efc5fb3abb2d1 (diff)
downloadunit-5a003df1fedc45ba091e947a9d7b7f2351d6edb6.tar.gz
unit-5a003df1fedc45ba091e947a9d7b7f2351d6edb6.tar.bz2
HTTP parser: fixed parsing of field values ending with space.
This closes #82 issue on GitHub.
Diffstat (limited to '')
-rw-r--r--src/nxt_http_parse.c18
-rw-r--r--src/test/nxt_http_parse_test.c6
2 files changed, 16 insertions, 8 deletions
diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c
index 65de0d60..f8249abb 100644
--- a/src/nxt_http_parse.c
+++ b/src/nxt_http_parse.c
@@ -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);
}
diff --git a/src/test/nxt_http_parse_test.c b/src/test/nxt_http_parse_test.c
index adf35168..d00fc1af 100644
--- a/src/test/nxt_http_parse_test.c
+++ b/src/test/nxt_http_parse_test.c
@@ -228,6 +228,12 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = {
},
{
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"),
NXT_DONE,
NULL, { NULL }