Skip to content

Commit

Permalink
Increase max IPv4 clientid. (#442)
Browse files Browse the repository at this point in the history
Remove arbitrary limit, raising to the maximum representable by uint8

Co-authored-by: Roy Marples <[email protected]>
  • Loading branch information
gnaaman-dn and rsmarples authored Feb 12, 2025
1 parent 0104902 commit 7e82f1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
17 changes: 10 additions & 7 deletions src/if-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -2469,7 +2471,8 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
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;
Expand Down
19 changes: 8 additions & 11 deletions src/if-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7e82f1c

Please sign in to comment.