]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dhcp: do not trigger assertion by malformed messages
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 15 Nov 2023 17:17:22 +0000 (02:17 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 15 Nov 2023 17:32:12 +0000 (02:32 +0900)
This also changes error code from -ENODATA -> -EBADMSG,
as we received bad message in that case.

Prompted by #30029.

src/libsystemd-network/sd-dhcp-lease.c
src/libsystemd-network/test-sd-dhcp-lease.c

index 4925fa8f1935b81da404a31b1358a1c0b703c963..4e3be98a33a2001890987c04c369ca30aa6e3d02 100644 (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;
index 3eea1b0d9b83a3e3f877f64f029fc19a9f273a76..910b622191c51b6f58ec95c106cfb0d57b9976cf 100644 (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) {