]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp6-client: make dhcp6_option_append_fqdn() or friends handle zero length value...
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 1 Oct 2022 06:31:50 +0000 (15:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 2 Oct 2022 14:05:05 +0000 (23:05 +0900)
src/libsystemd-network/dhcp6-option.c
src/libsystemd-network/dhcp6-option.h
src/libsystemd-network/sd-dhcp6-client.c

index 0d26aef234764f4df7dce9d5e86d6da8c7060fe3..4fd75fbf3b7f865af70a933eaa740d3b8ff9cacb 100644 (file)
@@ -256,7 +256,6 @@ int dhcp6_option_append_vendor_option(uint8_t **buf, size_t *buflen, OrderedSet
         assert(buf);
         assert(*buf);
         assert(buflen);
-        assert(vendor_options);
 
         ORDERED_SET_FOREACH(options, vendor_options) {
                 _cleanup_free_ uint8_t *p = NULL;
@@ -401,7 +400,9 @@ int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn) {
         assert(buf);
         assert(*buf);
         assert(buflen);
-        assert(fqdn);
+
+        if (isempty(fqdn))
+                return 0;
 
         buffer[0] = DHCP6_FQDN_FLAG_S; /* Request server to perform AAAA RR DNS updates */
 
@@ -431,7 +432,9 @@ int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char * const *
         assert(buf);
         assert(*buf);
         assert(buflen);
-        assert(!strv_isempty(user_class));
+
+        if (strv_isempty(user_class))
+                return 0;
 
         STRV_FOREACH(s, user_class) {
                 size_t len = strlen(*s);
@@ -463,7 +466,9 @@ int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char * const
         assert(buf);
         assert(*buf);
         assert(buflen);
-        assert(!strv_isempty(vendor_class));
+
+        if (strv_isempty(vendor_class))
+                return 0;
 
         enterprise_identifier = htobe32(SYSTEMD_PEN);
 
index 80aba7f37f13032c5b247e6b87921f7d48f2cdbf..d0442221241aec52d73ed873782fa2ed09456aae 100644 (file)
@@ -77,7 +77,7 @@ int dhcp6_option_append(uint8_t **buf, size_t *buflen, uint16_t code,
 int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, const DHCP6IA *ia);
 int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn);
 int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char * const *user_class);
-int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char * const *user_class);
+int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char * const *vendor_class);
 int dhcp6_option_append_vendor_option(uint8_t **buf, size_t *buflen, OrderedSet *vendor_options);
 
 int dhcp6_option_parse(
index b774772229bb87aeed23f7a2141d4c57acb19e0b..2704e1ca5a99503bcb7d238df370df491fe575ee 100644 (file)
@@ -602,29 +602,21 @@ static int client_append_common_options_in_managed_mode(
                         return r;
         }
 
-        if (client->fqdn) {
-                r = dhcp6_option_append_fqdn(opt, optlen, client->fqdn);
-                if (r < 0)
-                        return r;
-        }
+        r = dhcp6_option_append_fqdn(opt, optlen, client->fqdn);
+        if (r < 0)
+                return r;
 
-        if (client->user_class) {
-                r = dhcp6_option_append_user_class(opt, optlen, client->user_class);
-                if (r < 0)
-                        return r;
-        }
+        r = dhcp6_option_append_user_class(opt, optlen, client->user_class);
+        if (r < 0)
+                return r;
 
-        if (client->vendor_class) {
-                r = dhcp6_option_append_vendor_class(opt, optlen, client->vendor_class);
-                if (r < 0)
-                        return r;
-        }
+        r = dhcp6_option_append_vendor_class(opt, optlen, client->vendor_class);
+        if (r < 0)
+                return r;
 
-        if (!ordered_set_isempty(client->vendor_options)) {
-                r = dhcp6_option_append_vendor_option(opt, optlen, client->vendor_options);
-                if (r < 0)
-                        return r;
-        }
+        r = dhcp6_option_append_vendor_option(opt, optlen, client->vendor_options);
+        if (r < 0)
+                return r;
 
         return 0;
 }