]> git.ipfire.org Git - thirdparty/bird.git/blobdiff - lib/ip.c
IPv6 address parser: fail on incomplete addresses
[thirdparty/bird.git] / lib / ip.c
index 9497248c3a1dacb82c1b7c3258cadf2757da400f..fcc72cafb4de5ee8e2c2c1fcafae24c1f6812399 100644 (file)
--- a/lib/ip.c
+++ b/lib/ip.c
@@ -245,7 +245,7 @@ ip4_pton(const char *a, ip4_addr *o)
     char *d, *c = strchr(a, '.');
     if (!c != !i)
       return 0;
-    l = strtoul(a, &d, 10);
+    l = bstrtoul10(a, &d);
     if (((d != c) && *d) || (l > 255))
       return 0;
     ia = (ia << 8) | l;
@@ -264,6 +264,9 @@ ip6_pton(const char *a, ip6_addr *o)
   int i, j, k, l, hfil;
   const char *start;
 
+  if (!a[0])                           /* Empty string check */
+    return 0;
+
   if (a[0] == ':')                     /* Leading :: */
   {
     if (a[1] != ':')
@@ -333,6 +336,8 @@ ip6_pton(const char *a, ip6_addr *o)
     for (; i>=hfil; i--)
       words[i] = 0;
   }
+  else if (i != 8)     /* Incomplete address */
+    return 0;
 
   /* Convert the address to ip6_addr format */
   for (i=0; i<4; i++)