summaryrefslogtreecommitdiff
path: root/src/libsystemd-network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-10-01 15:31:50 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-10-02 23:05:05 +0900
commit4ec5b5c7785b21d958118cb741c98654bcb9e25a (patch)
treebf8e6cee41735d4eedb61e8e98dc16b9cb05aae6 /src/libsystemd-network
parent93ed1c0eb9b9434ffc292f09f533dc0decad6318 (diff)
downloadsystemd-4ec5b5c7785b21d958118cb741c98654bcb9e25a.tar.gz
sd-dhcp6-client: make dhcp6_option_append_fqdn() or friends handle zero length value gracefully
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r--src/libsystemd-network/dhcp6-option.c13
-rw-r--r--src/libsystemd-network/dhcp6-option.h2
-rw-r--r--src/libsystemd-network/sd-dhcp6-client.c32
3 files changed, 22 insertions, 25 deletions
diff --git a/src/libsystemd-network/dhcp6-option.c b/src/libsystemd-network/dhcp6-option.c
index 0d26aef234..4fd75fbf3b 100644
--- a/src/libsystemd-network/dhcp6-option.c
+++ b/src/libsystemd-network/dhcp6-option.c
@@ -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);
diff --git a/src/libsystemd-network/dhcp6-option.h b/src/libsystemd-network/dhcp6-option.h
index 80aba7f37f..d044222124 100644
--- a/src/libsystemd-network/dhcp6-option.h
+++ b/src/libsystemd-network/dhcp6-option.h
@@ -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(
diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index b774772229..2704e1ca5a 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -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;
}