dhcp: be more careful when parsing strings from DHCP packets

Let's make sure there's no embedded 0 byte. Also, let's reset the string
if the length is zero.
This commit is contained in:
Lennart Poettering 2015-08-26 19:18:11 +02:00
parent 1ac608c9cc
commit 43f447b121
1 changed files with 6 additions and 2 deletions

View File

@ -287,13 +287,17 @@ static int lease_parse_string(const uint8_t *option, size_t len, char **ret) {
if (len >= 1) {
char *string;
if (memchr(option, 0, len))
return -EINVAL;
string = strndup((const char *)option, len);
if (!string)
return -errno;
return -ENOMEM;
free(*ret);
*ret = string;
}
} else
*ret = mfree(*ret);
return 0;
}