Skip to content

Instantly share code, notes, and snippets.

@kazeburo
Created November 17, 2014 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazeburo/20c29d05d4018c4e7688 to your computer and use it in GitHub Desktop.
Save kazeburo/20c29d05d4018c4e7688 to your computer and use it in GitHub Desktop.
infinite loop if header has multibyte characters
diff --git a/picohttpparser.c b/picohttpparser.c
index 10015b8..ee9904f 100644
--- a/picohttpparser.c
+++ b/picohttpparser.c
@@ -95,6 +95,7 @@ static const char* get_token_to_eol(const char* buf, const char* buf_end,
if ((likely((unsigned char)*buf < '\040') && likely(*buf != '\011')) || unlikely(*buf == '\177')) {
goto FOUND_CTL;
}
+ ++buf;
}
for (; ; ++buf) {
CHECK_EOF();
diff --git a/test.c b/test.c
index 0897dfd..f055d4d 100644
--- a/test.c
+++ b/test.c
@@ -72,7 +72,18 @@ static void test_request(void)
ok(bufis(headers[0].value, headers[0].value_len, "example.com"));
ok(bufis(headers[1].name, headers[1].name_len, "Cookie"));
ok(bufis(headers[1].value, headers[1].value_len, ""));
-
+
+ PARSE("GET /hoge HTTP/1.1\r\nHost: example.com\r\nUser-Agent: \343\201\262\343/1.0\r\n\r\n", 0, 0,
+ "multibyte included");
+ ok(num_headers == 2);
+ ok(bufis(method, method_len, "GET"));
+ ok(bufis(path, path_len, "/hoge"));
+ ok(minor_version == 1);
+ ok(bufis(headers[0].name, headers[0].name_len, "Host"));
+ ok(bufis(headers[0].value, headers[0].value_len, "example.com"));
+ ok(bufis(headers[1].name, headers[1].name_len, "User-Agent"));
+ ok(bufis(headers[1].value, headers[1].value_len, "\343\201\262\343/1.0"));
+
PARSE("GET / HTTP/1.0\r\nfoo: \r\nfoo: b\r\n \tc\r\n\r\n", 0, 0,
"parse multiline");
ok(num_headers == 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment