From 547553b0909c9ce10a3730baeff7c7d1f76c0ea6 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 21 Aug 2013 03:20:48 +0200 Subject: [PATCH] Further request method check strengthening. --- http_parser.c | 2 ++ test.c | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/http_parser.c b/http_parser.c index f97311b..c87186f 100644 --- a/http_parser.c +++ b/http_parser.c @@ -929,6 +929,7 @@ size_t http_parser_execute (http_parser *parser, } else if (parser->index == 2 && ch == 'P') { parser->method = HTTP_COPY; } else { + SET_ERRNO(HPE_INVALID_METHOD); goto error; } } else if (parser->method == HTTP_MKCOL) { @@ -941,6 +942,7 @@ size_t http_parser_execute (http_parser *parser, } else if (parser->index == 2 && ch == 'A') { parser->method = HTTP_MKACTIVITY; } else { + SET_ERRNO(HPE_INVALID_METHOD); goto error; } } else if (parser->method == HTTP_SUBSCRIBE) { diff --git a/test.c b/test.c index 06be2ca..b9a5ac3 100644 --- a/test.c +++ b/test.c @@ -3273,16 +3273,7 @@ main (void) /// REQUESTS - test_simple("hello world", HPE_INVALID_METHOD); test_simple("GET / HTP/1.1\r\n\r\n", HPE_INVALID_VERSION); - test_simple("GEM / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD); - test_simple("PUN / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD); - test_simple("PX / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD); - test_simple("SA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD); - - test_simple("ASDF / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD); - test_simple("PROPPATCHA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD); - test_simple("GETA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD); // Well-formed but incomplete test_simple("GET / HTTP/1.1\r\n" @@ -3326,13 +3317,23 @@ main (void) } static const char *bad_methods[] = { + "ASDF", "C******", + "COLA", + "GEM", + "GETA", "M****", + "MKCOLA", + "PROPPATCHA", + "PUN", + "PX", + "SA", + "hello world", 0 }; for (this_method = bad_methods; *this_method; this_method++) { char buf[200]; sprintf(buf, "%s / HTTP/1.1\r\n\r\n", *this_method); - test_simple(buf, HPE_UNKNOWN); + test_simple(buf, HPE_INVALID_METHOD); } const char *dumbfuck2 =