Control: tags -1 + upstream wontfix

Hello Salvo Tomaselli,

Thanks for your bug report.

On Mon, Jun 26, 2017 at 12:54:22PM +0200, Salvo Tomaselli wrote:
[...]
> ip addr add 10.3 dev eth0
> will add an address 10.3.0.0
> 
> Everything else, normally, resolves 10.3 as 10.0.0.3. Because that's the libc
> resolver's behaviour.
> 
> ifconfig, wget, qt programs, browsers, will all use this format.
> 
> If ip can't support this format, it should just fail instead of parsing it
> differently than everything else.

This in intentional and documented in the source. Please feel free
to argue your case on the upstream mailing list. Below is the relevant
commit that you want to suggest being reverted. I'm tagging the
bug accordingly since I have no interest in deviating from upstreams
compatibility stance which would result in breaking existing compatibility
in Debian as well as deviating from the behaviour of the same tool in
other distributions.

Regards,
Andreas Henriksson


commit cafa6c8ec1d6e4bddde190edb742be864ce3f9b3
Author: Stephen Hemminger <stephen.hemmin...@vyatta.com>
Date:   Mon Oct 27 10:27:27 2008 -0700

    Restore old address parsing but with checking
    
    Go back to original address parsing for compatability, but
    document it and add more stringent checking.

diff --git a/lib/utils.c b/lib/utils.c
index bcc6a730..0bb08325 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -244,11 +244,39 @@ int get_s8(__s8 *val, const char *arg, int base)
        return 0;
 }
 
-int get_addr_1(inet_prefix *addr, const char *name, int family)
+/* This uses a non-standard parsing (ie not inet_aton, or inet_pton)
+ * because of legacy choice to parse 10.8 as 10.8.0.0 not 10.0.0.8
+ */
+static int get_addr_ipv4(__u8 *ap, const char *cp)
 {
-       unsigned long n;
-       char *endp;
+       int i;
+
+       for (i = 0; i < 4; i++) {
+               unsigned long n;
+               char *endp;
+               
+               n = strtoul(cp, &endp, 0);
+               if (n > 255)
+                       return -1;      /* bogus network value */
+
+               if (endp == cp) /* no digits */
+                       return -1;
+
+               ap[i] = n;
+
+               if (*endp == '\0')
+                       break;
+
+               if (i == 3 || *endp != '.')
+                       return -1;      /* extra characters */
+               cp = endp + 1;
+       }
 
+       return 1;
+}
+
+int get_addr_1(inet_prefix *addr, const char *name, int family)
+{
        memset(addr, 0, sizeof(*addr));
 
        if (strcmp(name, "default") == 0 ||
@@ -288,22 +316,7 @@ int get_addr_1(inet_prefix *addr, const char *name, int 
family)
        if (family != AF_UNSPEC && family != AF_INET)
                return -1;
 
-       n = strtoul(name, &endp, 0);
-       if (n > 255)
-               return -1;      /* bogus network value */
-
-       if (endp == name)       /* not a number */
-               return -1;
-
-       /* compatable with older usage (ie 10/8 = 10.0.0.0/8) */
-       if (strchr(name, '.') == NULL) {
-               addr->data[0] = n;
-               addr->bytelen = 4;
-               addr->bitlen = -1;
-               return 0;
-       }
-
-       if (inet_aton(name, (struct in_addr *)addr->data) <= 0)
+       if (get_addr_ipv4((__u8 *)addr->data, name) <= 0)
                return -1;
 
        addr->bytelen = 4;

Reply via email to