Message ID | 20220616000231.1966008-1-andrew.zaborowski@intel.com (mailing list archive) |
---|---|
State | Accepted, archived |
Headers | show |
Series | [01/15] netconfig: Fix address format validation | expand |
Hi Andrew, On 6/15/22 19:02, Andrew Zaborowski wrote: > Drop the wrong negation in the error check. Check that there are no extra > characters after prefix length suffix. Reset errno 0 before the strtoul > call, as recommended by the manpage. > --- > src/netconfig.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > Applied, thanks. Regards, -Denis
diff --git a/src/netconfig.c b/src/netconfig.c index 2ab03b90..4a70b0ca 100644 --- a/src/netconfig.c +++ b/src/netconfig.c @@ -515,6 +515,7 @@ static struct l_rtnl_address *netconfig_get_static6_address( { L_AUTO_FREE_VAR(char *, ip); char *p; + char *endp; struct l_rtnl_address *ret; uint32_t prefix_len = 128; @@ -530,8 +531,9 @@ static struct l_rtnl_address *netconfig_get_static6_address( if (*++p == '\0') goto no_prefix_len; - prefix_len = strtoul(p, NULL, 10); - if (!unlikely(errno == EINVAL || errno == ERANGE || + errno = 0; + prefix_len = strtoul(p, &endp, 10); + if (unlikely(*endp != '\0' || errno || !prefix_len || prefix_len > 128)) { l_error("netconfig: Invalid prefix '%s' provided in network" " configuration file", p);