handle interface unit numbers up to 2G-1; skip if total name is too long
authorderaadt <deraadt@openbsd.org>
Sat, 3 Feb 1996 20:06:27 +0000 (20:06 +0000)
committerderaadt <deraadt@openbsd.org>
Sat, 3 Feb 1996 20:06:27 +0000 (20:06 +0000)
sys/net/if.c

index 8fd2138..9b6f22c 100644 (file)
@@ -580,15 +580,23 @@ ifconf(cmd, data)
        register char *cp, *ep;
        struct ifreq ifr, *ifrp;
        int space = ifc->ifc_len, error = 0;
+       int i, ndig;
 
        ifrp = ifc->ifc_req;
-       ep = ifr.ifr_name + sizeof (ifr.ifr_name) - 2;
+       ep = ifr.ifr_name + sizeof (ifr.ifr_name);
        for (ifp = ifnet.tqh_first;
            space > sizeof (ifr) && ifp != 0; ifp = ifp->if_list.tqe_next) {
                strncpy(ifr.ifr_name, ifp->if_name, sizeof(ifr.ifr_name) - 2);
                for (cp = ifr.ifr_name; cp < ep && *cp; cp++)
                        continue;
-               *cp++ = '0' + ifp->if_unit; *cp = '\0';
+               for (i = ifp->if_unit, ndig = 0; i; i /= 10)
+                       ndig++;
+               cp += ndig;
+               if (cp >= ep)
+                       continue;
+               *cp = '\0';
+               for (i = ifp->if_unit; i; i /= 10)
+                       *--cp = '0' + (i % 10);
                if ((ifa = ifp->if_addrlist.tqh_first) == 0) {
                        bzero((caddr_t)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
                        error = copyout((caddr_t)&ifr, (caddr_t)ifrp,