From ba1253df3b2b087e7210fb28cc90f3049a423d9b Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Thu, 16 Jun 2022 02:02:17 +0200 Subject: [PATCH] netconfig: Fix address format validation 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(-) 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);