[PATCH] Two bugs in URL parsing from commit c419542d (bug #68295, #68296)
"Dainard, Samuel" via Primary discussion list for GNU Wget <[email protected]> Tue, 16 Jun 2026 21:50:52 +0000
| Newsgroups | gmane.comp.web.wget.general |
|---|---|
| Message-ID | <IA2PR18MB60535908EE2050655C837C4CA5E52@IA2PR18MB6053.namprd18.prod.outlook.com> |
Hi,
I filed two related bug reports on Savannah about seven weeks ago for issue=
s introduced in commit c419542d. Both have patches attached but haven't got=
ten any response yet. Known wget is high priority so hope y'all don't mind =
me sending them to the list for visibility.
Bug #68295 - is_valid_port: undefined behavior with atoi on overflow
https://savannah.gnu.org/bugs/?68295 (https://savannah.gnu.org/bugs/?6829=
5)
is_valid_port() uses atoi() to parse the port string. Since atoi() has unde=
fined behavior on integer overflow, a string like "99999999999" triggers UB=
before the range check can reject it. The patch replaces atoi() with strto=
ul(), which sets errno on overflow and whose end pointer eliminates the sep=
arate strspn() call.
Bug #68296 - maybe_prepend_scheme: strchr finds colons in path component
https://savannah.gnu.org/bugs/?68296 (https://savannah.gnu.org/bugs/?6829=
6)
maybe_prepend_scheme() uses strchr(url, ':') which matches colons anywhere =
in the URL, including the path. A schemeless URL like www.example.com/path:=
name (http://www.example.com/path:name)<http://www.example.com/path:name%20=
(http:/www.example.com/path:name)> hits the colon in "path:name", is_valid_=
port("name") returns false, and the function refuses to prepend http://. Th=
e patch adds a slash check so the colon search is limited to the authority =
component, restoring the behavior of the previous strpbrk(url, ":/") approa=
ch without reintroducing removed shorthand URL support.
Patches are on the respective bug reports. Happy to rebase or rework if nee=
ded.
Thanks,
Samuel Dainard
sdainard@