[vlc-commits] text/url: fix port handling in vlc_UrlParse

Filip Roséen git at videolan.org
Fri Oct 28 19:09:36 CEST 2016


vlc | branch: master | Filip Roséen <filip at atch.se> | Fri Oct 28 14:46:10 2016 +0200| [be6b2bced6d43e4bd4dcd0da7d7d4e6a22f2b23b] | committer: Thomas Guillem

text/url: fix port handling in vlc_UrlParse

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).

refs #17555

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=be6b2bced6d43e4bd4dcd0da7d7d4e6a22f2b23b
---

 src/text/url.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/text/url.c b/src/text/url.c
index 90a51cb..b9e7b41 100644
--- a/src/text/url.c
+++ b/src/text/url.c
@@ -525,18 +525,18 @@ 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)
+            {
+                errno = EINVAL;
                 ret = -1;
-#endif
+            }
+
+            url->i_port = port;
         }
 
         if (url->psz_path != NULL)



More information about the vlc-commits mailing list