]> granicus.if.org Git - curl/commitdiff
fix_hostname: zero length host name caused -1 index offset
authorDaniel Stenberg <daniel@haxx.se>
Thu, 16 Apr 2015 21:52:04 +0000 (23:52 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 21 Apr 2015 21:20:36 +0000 (23:20 +0200)
If a URL is given with a zero-length host name, like in "http://:80" or
just ":80", `fix_hostname()` will index the host name pointer with a -1
offset (as it blindly assumes a non-zero length) and both read and
assign that address.

CVE-2015-3144

Bug: http://curl.haxx.se/docs/adv_20150422D.html
Reported-by: Hanno Böck
lib/url.c

index ee3d176d9612e659a8f14679b4828c0b402b6f8e..f033dbc9566412c406bd8986e1c7cccb92e4be2c 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -3627,7 +3627,7 @@ static void fix_hostname(struct SessionHandle *data,
   host->dispname = host->name;
 
   len = strlen(host->name);
-  if(host->name[len-1] == '.')
+  if(len && (host->name[len-1] == '.'))
     /* strip off a single trailing dot if present, primarily for SNI but
        there's no use for it */
     host->name[len-1]=0;