dhcp: do not trigger assertion by malformed messages
This also changes error code from -ENODATA -> -EBADMSG, as we received bad message in that case. Prompted by #30029.
This commit is contained in:
@@ -931,7 +931,10 @@ int dhcp_lease_parse_search_domains(const uint8_t *option, size_t len, char ***d
|
||||
int r;
|
||||
|
||||
assert(domains);
|
||||
assert_return(option && len > 0, -ENODATA);
|
||||
assert(option || len == 0);
|
||||
|
||||
if (len == 0)
|
||||
return -EBADMSG;
|
||||
|
||||
while (pos < len) {
|
||||
_cleanup_free_ char *name = NULL;
|
||||
|
||||
@@ -60,8 +60,8 @@ TEST(dhcp_lease_parse_search_domains_no_data) {
|
||||
_cleanup_strv_free_ char **domains = NULL;
|
||||
static const uint8_t optionbuf[3] = {0, 0, 0};
|
||||
|
||||
assert_se(dhcp_lease_parse_search_domains(NULL, 0, &domains) == -ENODATA);
|
||||
assert_se(dhcp_lease_parse_search_domains(optionbuf, 0, &domains) == -ENODATA);
|
||||
assert_se(dhcp_lease_parse_search_domains(NULL, 0, &domains) == -EBADMSG);
|
||||
assert_se(dhcp_lease_parse_search_domains(optionbuf, 0, &domains) == -EBADMSG);
|
||||
}
|
||||
|
||||
TEST(dhcp_lease_parse_search_domains_loops) {
|
||||
|
||||
Reference in New Issue
Block a user