Date: Wed, 1 Sep 2010 20:25:36 +0000 (UTC) From: Ed Maste <emaste@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r212114 - stable/8/sbin/ifconfig Message-ID: <201009012025.o81KPahi079880@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: emaste Date: Wed Sep 1 20:25:36 2010 New Revision: 212114 URL: http://svn.freebsd.org/changeset/base/212114 Log: MFC r202289: Reject invalid CIDR widths rather than silently stopping at the first non-digit character. Due to an issue with rc(8) in a test configuration, ifconfig was being invoked with the address used again as the width - for example, ifconfig vlan0 10.0.0.1/10.0.0.1 Prior to this change, that address/width would be interpreted as 10.0.0.1/10. Modified: stable/8/sbin/ifconfig/af_inet.c Directory Properties: stable/8/sbin/ifconfig/ (props changed) Modified: stable/8/sbin/ifconfig/af_inet.c ============================================================================== --- stable/8/sbin/ifconfig/af_inet.c Wed Sep 1 19:53:15 2010 (r212113) +++ stable/8/sbin/ifconfig/af_inet.c Wed Sep 1 20:25:36 2010 (r212114) @@ -37,6 +37,7 @@ static const char rcsid[] = #include <sys/socket.h> #include <net/if.h> +#include <ctype.h> #include <err.h> #include <stdio.h> #include <stdlib.h> @@ -110,15 +111,18 @@ in_getaddr(const char *s, int which) char *p = NULL; if((p = strrchr(s, '/')) != NULL) { + const char *errstr; /* address is `name/masklen' */ int masklen; - int ret; struct sockaddr_in *min = sintab[MASK]; *p = '\0'; - ret = sscanf(p+1, "%u", &masklen); - if(ret != 1 || (masklen < 0 || masklen > 32)) { + if (!isdigit(*(p + 1))) + errstr = "invalid"; + else + masklen = (int)strtonum(p + 1, 0, 32, &errstr); + if (errstr != NULL) { *p = '/'; - errx(1, "%s: bad value", s); + errx(1, "%s: bad value (width %s)", s, errstr); } min->sin_len = sizeof(*min); min->sin_addr.s_addr = htonl(~((1LL << (32 - masklen)) - 1) &
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201009012025.o81KPahi079880>