diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-01-12 21:47:23 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-01-13 00:00:56 +0900 |
commit | e4336c0a5df42f4c88ed31c4bad743b93b69718f (patch) | |
tree | f47eabfb9769385a6c84e53c6726c47bc867c356 /src/libsystemd-network/dhcp-option.c | |
parent | b433300e4cd5cc9ea6a3240b8d5755fd62c26d99 (diff) | |
download | systemd-e4336c0a5df42f4c88ed31c4bad743b93b69718f.tar.gz |
dhcp: length of each user class field must be positive
This also fixes an memory leak when sd_dhcp_client_set_user_class()
is called multiple times.
Diffstat (limited to 'src/libsystemd-network/dhcp-option.c')
-rw-r--r-- | src/libsystemd-network/dhcp-option.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/libsystemd-network/dhcp-option.c b/src/libsystemd-network/dhcp-option.c index 70753c68d8..7e3fe4348b 100644 --- a/src/libsystemd-network/dhcp-option.c +++ b/src/libsystemd-network/dhcp-option.c @@ -38,11 +38,14 @@ static int option_append(uint8_t options[], size_t size, size_t *offset, size_t total = 0; char **s; + if (strv_isempty((char **) optval)) + return -EINVAL; + STRV_FOREACH(s, (char **) optval) { size_t len = strlen(*s); - if (len > 255) - return -ENAMETOOLONG; + if (len > 255 || len == 0) + return -EINVAL; total += 1 + len; } @@ -51,14 +54,13 @@ static int option_append(uint8_t options[], size_t size, size_t *offset, return -ENOBUFS; options[*offset] = code; - options[*offset + 1] = total; + options[*offset + 1] = total; *offset += 2; STRV_FOREACH(s, (char **) optval) { size_t len = strlen(*s); options[*offset] = len; - memcpy(&options[*offset + 1], *s, len); *offset += 1 + len; } |