From: deraadt Date: Sat, 3 Feb 1996 20:06:27 +0000 (+0000) Subject: handle interface unit numbers up to 2G-1; skip if total name is too long X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b17d5b884abd871d851c5e88a4f0f7d8719b2780;p=openbsd handle interface unit numbers up to 2G-1; skip if total name is too long --- diff --git a/sys/net/if.c b/sys/net/if.c index 8fd2138f43f..9b6f22c4465 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -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,