inet_pton(3) patch

Tatsuya BIZENN bizenn at visha.org
Sun Mar 25 07:34:34 PDT 2007


DragonFly's inet_pton(3) accepts also invalid IPv6 address form string.
I think it should be applied this patch below.  So inet_pton(3) become
the same one with NetBSD(it works properly).
--
Tatsuya BIZENN
Index: lib/libc/net/inet_pton.c
===================================================================
RCS file: /dcvs/src/lib/libc/net/inet_pton.c,v
retrieving revision 1.4
diff -u -r1.4 inet_pton.c
--- lib/libc/net/inet_pton.c    13 Nov 2005 02:04:47 -0000      1.4
+++ lib/libc/net/inet_pton.c    24 Mar 2007 14:34:31 -0000
@@ -88,6 +88,8 @@
                if ((pch = strchr(digits, ch)) != NULL) {
                        u_int new = *tp * 10 + (pch - digits);
+                       if (saw_digit && *tp == 0)
+                               return (0);
                        if (new > 255)
                                return (0);
                        *tp = new;
@@ -164,7 +166,8 @@
                                        return (0);
                                colonp = tp;
                                continue;
-                       }
+                       } else if (*src == '\0')
+                               return (0);
                        if (tp + NS_INT16SZ > endp)
                                return (0);
                        *tp++ = (u_char) (val >> 8) & 0xff;
@@ -195,6 +198,8 @@
                const int n = tp - colonp;
                int i;
+               if (tp == endp)
+                       return (0);
                for (i = 1; i <= n; i++) {
                        endp[- i] = colonp[n - i];
                        colonp[n - i] = 0;






More information about the Submit mailing list