From: Roy Marples Date: Fri, 29 May 2015 13:00:58 +0000 (+0000) Subject: Use strtoi(3) instead of sscanf(3) to grab CIDR from an address. X-Git-Tag: v6.9.1~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96dbe2c74bdb7870dcd294450a27a2914f8db92f;p=thirdparty%2Fdhcpcd.git Use strtoi(3) instead of sscanf(3) to grab CIDR from an address. --- diff --git a/if-options.c b/if-options.c index e231d351..aa3a351e 100644 --- a/if-options.c +++ b/if-options.c @@ -469,7 +469,6 @@ parse_addr(struct dhcpcd_ctx *ctx, struct in_addr *addr, struct in_addr *net, const char *arg) { char *p; - int i; if (arg == NULL || *arg == '\0') { if (addr != NULL) @@ -479,10 +478,13 @@ parse_addr(struct dhcpcd_ctx *ctx, return 0; } if ((p = strchr(arg, '/')) != NULL) { + int e; + intmax_t i; + *p++ = '\0'; - if (net != NULL && - (sscanf(p, "%d", &i) != 1 || - inet_cidrtoaddr(i, net) != 0)) + i = strtoi(p, NULL, 10, 0, 32, &e); + if (e != 0 || + (net != NULL && inet_cidrtoaddr((int)i, net) != 0)) { logger(ctx, LOG_ERR, "`%s' is not a valid CIDR", p); return -1;