]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd-network/dhcp-option.c
dhcp: length of each user class field must be positive
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-option.c
index 70753c68d847a160ef334eb9a0b6f2a427a8c3eb..7e3fe4348bb4ebd54c4d73f88ea0a37a06c3080d 100644 (file)
@@ -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;
                 }