net: utils: Check null pointer when parsing IPv6 address

We might access NULL pointer if strchr() return value is not
checked properly.

Coverity-CID: 187073
Fixes #8993

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2018-07-18 16:54:10 +03:00 committed by Anas Nashif
parent dfa3f10b26
commit 7f0432a114
1 changed files with 12 additions and 7 deletions

View File

@ -309,11 +309,14 @@ int net_addr_pton(sa_family_t family, const char *src,
UNALIGNED_PUT(htons(strtol(src, NULL, 16)),
&addr->s6_addr16[i]);
src = strchr(src, ':');
if (!src && i < expected_groups - 1) {
return -EINVAL;
if (src) {
src++;
} else {
if (i < expected_groups - 1) {
return -EINVAL;
}
}
src++;
continue;
}
@ -363,11 +366,13 @@ int net_addr_pton(sa_family_t family, const char *src,
addr->s6_addr[12 + i] = strtol(src, NULL, 10);
src = strchr(src, '.');
if (!src && i < 3) {
return -EINVAL;
if (src) {
src++;
} else {
if (i < 3) {
return -EINVAL;
}
}
src++;
}
}
} else {