Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Commit 303c4e4

Browse files
committed
Further request method check strengthening.
1 parent ddfa1b3 commit 303c4e4

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

http_parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ size_t http_parser_execute (http_parser *parser,
936936
} else if (parser->index == 2 && ch == 'P') {
937937
parser->method = HTTP_COPY;
938938
} else {
939+
SET_ERRNO(HPE_INVALID_METHOD);
939940
goto error;
940941
}
941942
} else if (parser->method == HTTP_MKCOL) {
@@ -948,6 +949,7 @@ size_t http_parser_execute (http_parser *parser,
948949
} else if (parser->index == 2 && ch == 'A') {
949950
parser->method = HTTP_MKACTIVITY;
950951
} else {
952+
SET_ERRNO(HPE_INVALID_METHOD);
951953
goto error;
952954
}
953955
} else if (parser->method == HTTP_SUBSCRIBE) {

test.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,16 +3117,7 @@ main (void)
31173117

31183118
/// REQUESTS
31193119

3120-
test_simple("hello world", HPE_INVALID_METHOD);
31213120
test_simple("GET / HTP/1.1\r\n\r\n", HPE_INVALID_VERSION);
3122-
test_simple("GEM / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
3123-
test_simple("PUN / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
3124-
test_simple("PX / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
3125-
test_simple("SA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
3126-
3127-
test_simple("ASDF / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
3128-
test_simple("PROPPATCHA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
3129-
test_simple("GETA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
31303121

31313122
// Well-formed but incomplete
31323123
test_simple("GET / HTTP/1.1\r\n"
@@ -3170,13 +3161,23 @@ main (void)
31703161
}
31713162

31723163
static const char *bad_methods[] = {
3164+
"ASDF",
31733165
"C******",
3166+
"COLA",
3167+
"GEM",
3168+
"GETA",
31743169
"M****",
3170+
"MKCOLA",
3171+
"PROPPATCHA",
3172+
"PUN",
3173+
"PX",
3174+
"SA",
3175+
"hello world",
31753176
0 };
31763177
for (this_method = bad_methods; *this_method; this_method++) {
31773178
char buf[200];
31783179
sprintf(buf, "%s / HTTP/1.1\r\n\r\n", *this_method);
3179-
test_simple(buf, HPE_UNKNOWN);
3180+
test_simple(buf, HPE_INVALID_METHOD);
31803181
}
31813182

31823183
const char *dumbfuck2 =

0 commit comments

Comments
 (0)