From 31232735c6a44036083da685c8dff253da78c99e Mon Sep 17 00:00:00 2001 From: Welling Guzman Date: Fri, 27 Apr 2018 05:04:29 -0400 Subject: [PATCH] Return nonzero on parsing empty url. Fixes: https://github.com/nodejs/http-parser/issues/414 PR-URL: https://github.com/nodejs/http-parser/pull/424 Reviewed-By: Ben Noordhuis --- http_parser.c | 4 ++++ test.c | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/http_parser.c b/http_parser.c index eeacef5..6e534c8 100644 --- a/http_parser.c +++ b/http_parser.c @@ -2314,6 +2314,10 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect, enum http_parser_url_fields uf, old_uf; int found_at = 0; + if (buflen == 0) { + return 1; + } + u->port = u->field_set = 0; s = is_connect ? s_req_server_start : s_req_spaces_before_url; old_uf = UF_MAX; diff --git a/test.c b/test.c index dcf5486..5a1735b 100644 --- a/test.c +++ b/test.c @@ -3250,6 +3250,24 @@ const struct url_test url_tests[] = ,.rv=1 /* s_dead */ } +, {.name="empty url" + ,.url="" + ,.is_connect=0 + ,.rv=1 + } + +, {.name="NULL url" + ,.url=NULL + ,.is_connect=0 + ,.rv=1 + } + +, {.name="full of spaces url" + ,.url=" " + ,.is_connect=0 + ,.rv=1 + } + #if HTTP_PARSER_STRICT , {.name="tab in URL" @@ -3334,7 +3352,7 @@ test_parse_url (void) memset(&u, 0, sizeof(u)); rv = http_parser_parse_url(test->url, - strlen(test->url), + test->url ? strlen(test->url) : 0, test->is_connect, &u);