]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Increase max IPv4 clientid. (#442)
authorGilad Naaman <70581924+gnaaman-dn@users.noreply.github.com>
Wed, 12 Feb 2025 15:29:39 +0000 (17:29 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Feb 2025 15:29:39 +0000 (15:29 +0000)
Remove arbitrary limit, raising to the maximum representable by uint8

Co-authored-by: Roy Marples <roy@marples.name>
src/if-options.c
src/if-options.h

index 54ae590b4a5948d506431a92451d2a5c59080e2c..faa22f90250d6fad7a63f6a61a038dcdb7b2f646 100644 (file)
@@ -762,7 +762,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
        case 'i':
                if (arg)
                        s = parse_string((char *)ifo->vendorclassid + 1,
-                           VENDORCLASSID_MAX_LEN, arg);
+                           sizeof(ifo->vendorclassid) - 1, arg);
                else
                        s = 0;
                if (s == -1) {
@@ -1049,7 +1049,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                if (p == arg) {
                        arg++;
                        s = parse_string((char *)ifo->vendor + 1,
-                           VENDOR_MAX_LEN, arg);
+                           sizeof(ifo->vendor) - 1, arg);
                        if (s == -1) {
                                logerr("vendor");
                                return -1;
@@ -1076,7 +1076,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                }
 
                arg = p + 1;
-               s = VENDOR_MAX_LEN - ifo->vendor[0] - 2;
+               s = sizeof(ifo->vendor) - 1 - ifo->vendor[0] - 2;
                if (inet_aton(arg, &addr) == 1) {
                        if (s < 6) {
                                s = -1;
@@ -1203,11 +1203,13 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                ifo->options |= DHCPCD_XID_HWADDR;
                break;
        case 'I':
-               /* Strings have a type of 0 */;
-               ifo->clientid[1] = 0;
                if (arg)
+                       /* If parse_hwaddr cannot decoded arg as a
+                        * hardware address then the first byte
+                        * in the clientid will be zero to indicate
+                        * a string value. */
                        s = parse_hwaddr((char *)ifo->clientid + 1,
-                           CLIENTID_MAX_LEN, arg);
+                           sizeof(ifo->clientid) - 1, arg);
                else
                        s = 0;
                if (s == -1) {
@@ -2469,7 +2471,8 @@ invalid_token:
                break;
        case O_MUDURL:
                ARG_REQUIRED;
-               s = parse_string((char *)ifo->mudurl + 1, MUDURL_MAX_LEN, arg);
+               s = parse_string((char *)ifo->mudurl + 1,
+                   sizeof(ifo->mudurl) - 1, arg);
                if (s == -1) {
                        logerr("mudurl");
                        return -1;
index c892e75d5f8c33158a15283544fe2ad14d37cf51..cd02be1874c42b5e31acb0b7e5d2981a92a1e7c6 100644 (file)
 #ifndef HOSTNAME_MAX_LEN
 #define HOSTNAME_MAX_LEN       250     /* 255 - 3 (FQDN) - 2 (DNS enc) */
 #endif
-#define VENDORCLASSID_MAX_LEN  255
-#define CLIENTID_MAX_LEN       48
-#define USERCLASS_MAX_LEN      255
-#define VENDOR_MAX_LEN         255
-#define        MUDURL_MAX_LEN          255
+#define        DHCP_OPTION_MAX_LEN     255
 
 #define DHCPCD_ARP                     (1ULL << 0)
 #define DHCPCD_RELEASE                 (1ULL << 1)
@@ -274,13 +270,14 @@ struct if_options {
 
        char **environ;
 
-       char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the length */
+       char hostname[HOSTNAME_MAX_LEN + 1]; /* NUL terminated */
        uint8_t fqdn;
-       uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2];
-       uint8_t clientid[CLIENTID_MAX_LEN + 2];
-       uint8_t userclass[USERCLASS_MAX_LEN + 2];
-       uint8_t vendor[VENDOR_MAX_LEN + 2];
-       uint8_t mudurl[MUDURL_MAX_LEN + 2];
+       /* The first byte is the option length */
+       uint8_t vendorclassid[DHCP_OPTION_MAX_LEN + 1];
+       uint8_t clientid[DHCP_OPTION_MAX_LEN + 1];
+       uint8_t userclass[DHCP_OPTION_MAX_LEN + 1];
+       uint8_t vendor[DHCP_OPTION_MAX_LEN + 1];
+       uint8_t mudurl[DHCP_OPTION_MAX_LEN + 1];
 
        size_t blacklist_len;
        in_addr_t *blacklist;