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:
Yu Watanabe
2023-11-16 02:32:12 +09:00
parent 4f6ae86629
commit c0b927eb3a
2 changed files with 6 additions and 3 deletions
+4 -1
View File
@@ -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;
+2 -2
View File
@@ -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) {