3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00

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.
This commit is contained in:
Andrew Zaborowski 2022-06-16 02:02:17 +02:00 committed by Denis Kenzior
parent ef956995b8
commit ba1253df3b

View File

@ -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);