Skip to content

Commit 8d42c63

Browse files
committed
deps: upgrade http_parser to 303c4e4
Upgrade to nodejs/http-parser@303c4e4. Changes: * Do not accept PUN/GEM methods as PUT/GET. * Further request method check strengthening.
1 parent af6a233 commit 8d42c63

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

deps/http_parser/http_parser.c

Lines changed: 19 additions & 2 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,12 +949,14 @@ 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) {
954956
if (parser->index == 1 && ch == 'E') {
955957
parser->method = HTTP_SEARCH;
956958
} else {
959+
SET_ERRNO(HPE_INVALID_METHOD);
957960
goto error;
958961
}
959962
} else if (parser->index == 1 && parser->method == HTTP_POST) {
@@ -964,13 +967,27 @@ size_t http_parser_execute (http_parser *parser,
964967
} else if (ch == 'A') {
965968
parser->method = HTTP_PATCH;
966969
} else {
970+
SET_ERRNO(HPE_INVALID_METHOD);
967971
goto error;
968972
}
969973
} else if (parser->index == 2) {
970974
if (parser->method == HTTP_PUT) {
971-
if (ch == 'R') parser->method = HTTP_PURGE;
975+
if (ch == 'R') {
976+
parser->method = HTTP_PURGE;
977+
} else {
978+
SET_ERRNO(HPE_INVALID_METHOD);
979+
goto error;
980+
}
972981
} else if (parser->method == HTTP_UNLOCK) {
973-
if (ch == 'S') parser->method = HTTP_UNSUBSCRIBE;
982+
if (ch == 'S') {
983+
parser->method = HTTP_UNSUBSCRIBE;
984+
} else {
985+
SET_ERRNO(HPE_INVALID_METHOD);
986+
goto error;
987+
}
988+
} else {
989+
SET_ERRNO(HPE_INVALID_METHOD);
990+
goto error;
974991
}
975992
} else if (parser->index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') {
976993
parser->method = HTTP_PROPPATCH;

deps/http_parser/test.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,14 +3117,8 @@ 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);
31223121

3123-
3124-
test_simple("ASDF / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
3125-
test_simple("PROPPATCHA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
3126-
test_simple("GETA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
3127-
31283122
// Well-formed but incomplete
31293123
test_simple("GET / HTTP/1.1\r\n"
31303124
"Content-Type: text/plain\r\n"
@@ -3167,13 +3161,23 @@ main (void)
31673161
}
31683162

31693163
static const char *bad_methods[] = {
3164+
"ASDF",
31703165
"C******",
3166+
"COLA",
3167+
"GEM",
3168+
"GETA",
31713169
"M****",
3170+
"MKCOLA",
3171+
"PROPPATCHA",
3172+
"PUN",
3173+
"PX",
3174+
"SA",
3175+
"hello world",
31723176
0 };
31733177
for (this_method = bad_methods; *this_method; this_method++) {
31743178
char buf[200];
31753179
sprintf(buf, "%s / HTTP/1.1\r\n\r\n", *this_method);
3176-
test_simple(buf, HPE_UNKNOWN);
3180+
test_simple(buf, HPE_INVALID_METHOD);
31773181
}
31783182

31793183
const char *dumbfuck2 =

0 commit comments

Comments
 (0)