summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/dhcp6-option.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-01-12 22:03:43 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-01-13 00:00:56 +0900
commit5a99444e4fe80c2ed416ca402b437e780a9de4b8 (patch)
tree01c9856372353c69d679f3f123793bb84a54abb9 /src/libsystemd-network/dhcp6-option.c
parentb79951fa328f60577082a5710852e1d020d60b65 (diff)
downloadsystemd-5a99444e4fe80c2ed416ca402b437e780a9de4b8.tar.gz
dhcp6: refuse zero length dhcp user class
This also fixes a memory leak when sd_dhcp6_client_set_request_user_class() is called multiple times.
Diffstat (limited to 'src/libsystemd-network/dhcp6-option.c')
-rw-r--r--src/libsystemd-network/dhcp6-option.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/libsystemd-network/dhcp6-option.c b/src/libsystemd-network/dhcp6-option.c
index e2bf4f7e36..8151e66bca 100644
--- a/src/libsystemd-network/dhcp6-option.c
+++ b/src/libsystemd-network/dhcp6-option.c
@@ -200,19 +200,22 @@ int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn) {
return r;
}
-int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char **user_class) {
+int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char * const *user_class) {
_cleanup_free_ uint8_t *p = NULL;
size_t total = 0, offset = 0;
- char **s;
+ char * const *s;
- assert_return(buf && *buf && buflen && user_class, -EINVAL);
+ assert(buf);
+ assert(*buf);
+ assert(buflen);
+ assert(!strv_isempty(user_class));
STRV_FOREACH(s, user_class) {
size_t len = strlen(*s);
uint8_t *q;
- if (len > 0xffff)
- return -ENAMETOOLONG;
+ if (len > 0xffff || len == 0)
+ return -EINVAL;
q = realloc(p, total + len + 2);
if (!q)
return -ENOMEM;