]> git.proxmox.com Git - mirror_qemu.git/commitdiff
util/uri: Add overflow check to rfc3986_parse_port
authorMax Reitz <mreitz@redhat.com>
Wed, 25 Feb 2015 18:08:14 +0000 (13:08 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 18 Mar 2015 11:05:31 +0000 (12:05 +0100)
And while at it, replace tabs by eight spaces in this function.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <1424887718-10800-2-git-send-email-mreitz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
util/uri.c

index 1cfd78bdb53ac0217482e05308fccbfe72b900a0..550b9845870d850ce69829411ab92828c0f98658 100644 (file)
@@ -320,19 +320,23 @@ static int
 rfc3986_parse_port(URI *uri, const char **str)
 {
     const char *cur = *str;
+    int port = 0;
 
     if (ISA_DIGIT(cur)) {
-       if (uri != NULL)
-           uri->port = 0;
-       while (ISA_DIGIT(cur)) {
-           if (uri != NULL)
-               uri->port = uri->port * 10 + (*cur - '0');
-           cur++;
-       }
-       *str = cur;
-       return(0);
+        while (ISA_DIGIT(cur)) {
+            port = port * 10 + (*cur - '0');
+            if (port > 65535) {
+                return 1;
+            }
+            cur++;
+        }
+        if (uri) {
+            uri->port = port;
+        }
+        *str = cur;
+        return 0;
     }
-    return(1);
+    return 1;
 }
 
 /**