[vlc-devel] [PATCH 4/4] text/url: fix port handling in vlc_UrlParse
Filip Roséen
filip at atch.se
Fri Oct 28 10:49:47 CEST 2016
Differences compared to the previous implementation:
- accept URLs with empty port-specification (RFC3986, 3.2.3).
- reject port-specification with leading sign (RFC3986 only
allows *DIGIT).
- do not error on ULONG_MAX if strtoul did not detect an overflow
error (if ULONG_MAX == UINT_MAX on the target platform, this change
is important).
refs #17555
---
src/text/url.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/text/url.c b/src/text/url.c
index 90a51cb..c183bf1 100644
--- a/src/text/url.c
+++ b/src/text/url.c
@@ -525,18 +525,19 @@ int vlc_UrlParse(vlc_url_t *restrict url, const char *str)
}
/* Port number */
- if (next != NULL)
+ if (next != NULL && *next)
{
- char *end;
- unsigned long u = strtoul(next, &end, 10);
+ char* end;
+ unsigned long port = strtoul(next, &end, 10);
- url->i_port = u;
- if (end == next || *end != '\0' || u == ULONG_MAX)
- ret = -1;
-#if (ULONG_MAX > UINT_MAX)
- if (u > UINT_MAX)
+ if (strchr("0123456789", *next) == NULL || *end ||
+ port > UINT_MAX || (port == ULONG_MAX && errno == ERANGE))
+ {
+ errno = EINVAL;
ret = -1;
-#endif
+ }
+
+ url->i_port = port;
}
if (url->psz_path != NULL)
--
2.10.1
More information about the vlc-devel
mailing list