Skip to content

Commit 7e82f1c

Browse files
Increase max IPv4 clientid. (#442)
Remove arbitrary limit, raising to the maximum representable by uint8 Co-authored-by: Roy Marples <[email protected]>
1 parent 0104902 commit 7e82f1c

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/if-options.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
762762
case 'i':
763763
if (arg)
764764
s = parse_string((char *)ifo->vendorclassid + 1,
765-
VENDORCLASSID_MAX_LEN, arg);
765+
sizeof(ifo->vendorclassid) - 1, arg);
766766
else
767767
s = 0;
768768
if (s == -1) {
@@ -1049,7 +1049,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
10491049
if (p == arg) {
10501050
arg++;
10511051
s = parse_string((char *)ifo->vendor + 1,
1052-
VENDOR_MAX_LEN, arg);
1052+
sizeof(ifo->vendor) - 1, arg);
10531053
if (s == -1) {
10541054
logerr("vendor");
10551055
return -1;
@@ -1076,7 +1076,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
10761076
}
10771077

10781078
arg = p + 1;
1079-
s = VENDOR_MAX_LEN - ifo->vendor[0] - 2;
1079+
s = sizeof(ifo->vendor) - 1 - ifo->vendor[0] - 2;
10801080
if (inet_aton(arg, &addr) == 1) {
10811081
if (s < 6) {
10821082
s = -1;
@@ -1203,11 +1203,13 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
12031203
ifo->options |= DHCPCD_XID_HWADDR;
12041204
break;
12051205
case 'I':
1206-
/* Strings have a type of 0 */;
1207-
ifo->clientid[1] = 0;
12081206
if (arg)
1207+
/* If parse_hwaddr cannot decoded arg as a
1208+
* hardware address then the first byte
1209+
* in the clientid will be zero to indicate
1210+
* a string value. */
12091211
s = parse_hwaddr((char *)ifo->clientid + 1,
1210-
CLIENTID_MAX_LEN, arg);
1212+
sizeof(ifo->clientid) - 1, arg);
12111213
else
12121214
s = 0;
12131215
if (s == -1) {
@@ -2469,7 +2471,8 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
24692471
break;
24702472
case O_MUDURL:
24712473
ARG_REQUIRED;
2472-
s = parse_string((char *)ifo->mudurl + 1, MUDURL_MAX_LEN, arg);
2474+
s = parse_string((char *)ifo->mudurl + 1,
2475+
sizeof(ifo->mudurl) - 1, arg);
24732476
if (s == -1) {
24742477
logerr("mudurl");
24752478
return -1;

src/if-options.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@
5656
#ifndef HOSTNAME_MAX_LEN
5757
#define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */
5858
#endif
59-
#define VENDORCLASSID_MAX_LEN 255
60-
#define CLIENTID_MAX_LEN 48
61-
#define USERCLASS_MAX_LEN 255
62-
#define VENDOR_MAX_LEN 255
63-
#define MUDURL_MAX_LEN 255
59+
#define DHCP_OPTION_MAX_LEN 255
6460

6561
#define DHCPCD_ARP (1ULL << 0)
6662
#define DHCPCD_RELEASE (1ULL << 1)
@@ -274,13 +270,14 @@ struct if_options {
274270

275271
char **environ;
276272

277-
char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the length */
273+
char hostname[HOSTNAME_MAX_LEN + 1]; /* NUL terminated */
278274
uint8_t fqdn;
279-
uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2];
280-
uint8_t clientid[CLIENTID_MAX_LEN + 2];
281-
uint8_t userclass[USERCLASS_MAX_LEN + 2];
282-
uint8_t vendor[VENDOR_MAX_LEN + 2];
283-
uint8_t mudurl[MUDURL_MAX_LEN + 2];
275+
/* The first byte is the option length */
276+
uint8_t vendorclassid[DHCP_OPTION_MAX_LEN + 1];
277+
uint8_t clientid[DHCP_OPTION_MAX_LEN + 1];
278+
uint8_t userclass[DHCP_OPTION_MAX_LEN + 1];
279+
uint8_t vendor[DHCP_OPTION_MAX_LEN + 1];
280+
uint8_t mudurl[DHCP_OPTION_MAX_LEN + 1];
284281

285282
size_t blacklist_len;
286283
in_addr_t *blacklist;

0 commit comments

Comments
 (0)