8000 Return nonzero on parsing empty url. · nodejs/http-parser@3123273 · GitHub
[go: up one dir, main page]

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

Commit 3123273

Browse files
wellingguzmanbnoordhuis
authored andcommitted
Return nonzero on parsing empty url.
Fixes: #414 PR-URL: #424 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 2ed7527 commit 3123273

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

http_parser.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,6 +2314,10 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
23142314
enum http_parser_url_fields uf, old_uf;
23152315
int found_at = 0;
23162316

2317+
if (buflen == 0) {
2318+
return 1;
2319+
}
2320+
23172321
u->port = u->field_set = 0;
23182322
s = is_connect ? s_req_server_start : s_req_spaces_before_url;
23192323
old_uf = UF_MAX;

test.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3250,6 +3250,24 @@ const struct url_test url_tests[] =
32503250
,.rv=1 /* s_dead */
32513251
}
32523252

3253+
, {.name="empty url"
3254+
,.url=""
3255+
,.is_connect=0
3256+
,.rv=1
3257+
}
3258+
3259+
, {.name="NULL url"
3260+
,.url=NULL
3261+
,.is_connect=0
3262+
,.rv=1
3263+
}
3264+
3265+
, {.name="full of spaces url"
3266+
,.url=" "
3267+
,.is_connect=0
3268+
,.rv=1
3269+
}
3270+
32533271
#if HTTP_PARSER_STRICT
32543272

32553273
, {.name="tab in URL"
@@ -3334,7 +3352,7 @@ test_parse_url (void)
33343352
memset(&u, 0, sizeof(u));
33353353

33363354
rv = http_parser_parse_url(test->url,
3337-
strlen(test->url),
3355+
test->url ? strlen(test->url) : 0,
33383356
test->is_connect,
33393357
&u);
33403358

0 commit comments

Comments
 (0)
0