From a6ab773f19fb1b8d30d040dac9a012129b11ea84 Mon Sep 17 00:00:00 2001 From: Ichito Nagata Date: Thu, 16 May 2019 16:10:00 +0900 Subject: [PATCH] accept multiple whitespaces between tokens --- picohttpparser.c | 11 +++++++---- test.c | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/picohttpparser.c b/picohttpparser.c index d5002d5..b1193b7 100644 --- a/picohttpparser.c +++ b/picohttpparser.c @@ -359,9 +359,9 @@ static const char *parse_request(const char *buf, const char *buf_end, const cha /* parse request line */ ADVANCE_TOKEN(*method, *method_len); - ++buf; + while (*buf == ' ') ++buf; ADVANCE_TOKEN(*path, *path_len); - ++buf; + while (*buf == ' ') ++buf; if (*method_len == 0 || *path_len == 0) { *ret = -1; return NULL; @@ -422,6 +422,7 @@ static const char *parse_response(const char *buf, const char *buf_end, int *min *ret = -1; return NULL; } + while (*buf == ' ') ++buf; /* parse status code, we want at least [:digit:][:digit:][:digit:] to try to parse */ if (buf_end - buf < 4) { *ret = -2; @@ -437,8 +438,10 @@ static const char *parse_response(const char *buf, const char *buf_end, int *min /* ok */ } else if (**msg == ' ') { /* remove preceding space */ - ++*msg; - --*msg_len; + while (**msg == ' ') { + ++*msg; + --*msg_len; + } } else { /* garbage found after status code */ *ret = -1; diff --git a/test.c b/test.c index 2a93477..abcd0a9 100644 --- a/test.c +++ b/test.c @@ -146,6 +146,8 @@ static void test_request(void) PARSE("GET / HTTP/1.0\r\nfoo: a \t \r\n\r\n", 0, 0, "exclude leading and trailing spaces in header value"); ok(bufis(headers[0].value, headers[0].value_len, "a")); + PARSE("GET / HTTP/1.0\r\n\r\n", 0, 0, "accept multiple spaces between tokens"); + #undef PARSE } @@ -245,6 +247,8 @@ static void test_response(void) PARSE("HTTP/1.1 200 OK\r\nbar: \t b\t \t\r\n\r\n", 0, 0, "exclude leading and trailing spaces in header value"); ok(bufis(headers[0].value, headers[0].value_len, "b")); + PARSE("HTTP/1.1 200 OK\r\n\r\n", 0, 0, "accept multiple spaces between tokens"); + #undef PARSE }