Fix crash on improperly terminated IPv6 addresses

Hrvoje Niksic <[email protected]> Fri, 01 Jul 2005 19:15:49 +0200
Newsgroups gmane.comp.web.wget.patches
Message-ID <[email protected]>
Instant crash in Wget 1.10:

    wget "http://[::1]haha"

This patch fixes the problem for 1.10; 1.11 will receive a different
fix.


2005-07-01  Hrvoje Niksic  <[email protected]>

	* url.c (url_parse): Don't crash on []-delimited IPv6 addresses
	followed by garbage.

Index: src/url.c
===================================================================
--- src/url.c	(revision 1838)
+++ src/url.c	(working copy)
@@ -626,8 +626,8 @@
   N_("No error"),
 #define PE_UNSUPPORTED_SCHEME		1
   N_("Unsupported scheme"),
-#define PE_EMPTY_HOST			2
-  N_("Empty host"),
+#define PE_INVALID_HOST_NAME		2
+  N_("Invalid host name"),
 #define PE_BAD_PORT_NUMBER		3
   N_("Bad port number"),
 #define PE_INVALID_USER_NAME		4
@@ -727,6 +727,17 @@
       error_code = PE_IPV6_NOT_SUPPORTED;
       goto err;
 #endif
+
+      /* The closing bracket must be followed by a separator or by the
+	 null char.  */
+      /* http://[::1]... */
+      /*             ^   */
+      if (!strchr (":/;?#", *p))
+	{
+	  /* Trailing garbage after []-delimited IPv6 address. */
+	  error_code = PE_INVALID_HOST_NAME;
+	  goto err;
+	}
     }
   else
     {
@@ -736,7 +747,7 @@
 
   if (host_b == host_e)
     {
-      error_code = PE_EMPTY_HOST;
+      error_code = PE_INVALID_HOST_NAME;
       goto err;
     }