From: Gilad Naaman <70581924+gnaaman-dn@users.noreply.github.com> Date: Wed, 12 Feb 2025 15:29:39 +0000 (+0200) Subject: Increase max IPv4 clientid. (#442) X-Git-Tag: v10.2.0~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7e82f1c5ebb61d4bea3974301242ed0029c9300a;p=thirdparty%2Fdhcpcd.git Increase max IPv4 clientid. (#442) Remove arbitrary limit, raising to the maximum representable by uint8 Co-authored-by: Roy Marples --- diff --git a/src/if-options.c b/src/if-options.c index 54ae590b..faa22f90 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -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; diff --git a/src/if-options.h b/src/if-options.h index c892e75d..cd02be18 100644 --- a/src/if-options.h +++ b/src/if-options.h @@ -56,11 +56,7 @@ #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;