]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: refuse zero length dhcp user class
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 12 Jan 2021 12:55:15 +0000 (21:55 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 12 Jan 2021 15:00:56 +0000 (00:00 +0900)
src/network/networkd-dhcp-common.c

index 4dd98a2c61ed1ce2d40be125c0fa8b95df31a8c0..4826d15e808f684de94d99ca641c744175c1d1fb 100644 (file)
@@ -533,6 +533,7 @@ int config_parse_dhcp_user_class(
 
         for (const char *p = rvalue;;) {
                 _cleanup_free_ char *w = NULL;
+                size_t len;
 
                 r = extract_first_word(&p, &w, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
                 if (r == -ENOMEM)
@@ -545,25 +546,24 @@ int config_parse_dhcp_user_class(
                 if (r == 0)
                         return 0;
 
+                len = strlen(w);
                 if (ltype == AF_INET) {
-                        if (strlen(w) > UINT8_MAX) {
+                        if (len > UINT8_MAX || len == 0) {
                                 log_syntax(unit, LOG_WARNING, filename, line, 0,
                                            "%s length is not in the range 1-255, ignoring.", w);
                                 continue;
                         }
                 } else {
-                        if (strlen(w) > UINT16_MAX) {
+                        if (len > UINT16_MAX || len == 0) {
                                 log_syntax(unit, LOG_WARNING, filename, line, 0,
                                            "%s length is not in the range 1-65535, ignoring.", w);
                                 continue;
                         }
                 }
 
-                r = strv_push(l, w);
+                r = strv_consume(l, TAKE_PTR(w));
                 if (r < 0)
                         return log_oom();
-
-                w = NULL;
         }
 }