Skip to content

Commit 957d47f

Browse files
committed
dhcp: get_option_uint* only accept options with correct len
RFC8925 mentions "The client MUST ignore the IPv6-Only Preferred option if the length field value is not 4."
1 parent ab5ec18 commit 957d47f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/dhcp.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ get_option_uint32(struct dhcpcd_ctx *ctx,
304304
uint32_t d;
305305

306306
p = get_option(ctx, bootp, bootp_len, option, &len);
307-
if (!p || len < (ssize_t)sizeof(d))
307+
if (!p || len != (ssize_t)sizeof(d))
308308
return -1;
309309
memcpy(&d, p, sizeof(d));
310310
if (i)
@@ -321,7 +321,7 @@ get_option_uint16(struct dhcpcd_ctx *ctx,
321321
uint16_t d;
322322

323323
p = get_option(ctx, bootp, bootp_len, option, &len);
324-
if (!p || len < (ssize_t)sizeof(d))
324+
if (!p || len != (ssize_t)sizeof(d))
325325
return -1;
326326
memcpy(&d, p, sizeof(d));
327327
if (i)
@@ -337,7 +337,7 @@ get_option_uint8(struct dhcpcd_ctx *ctx,
337337
size_t len;
338338

339339
p = get_option(ctx, bootp, bootp_len, option, &len);
340-
if (!p || len < (ssize_t)sizeof(*p))
340+
if (!p || len != (ssize_t)sizeof(*p))
341341
return -1;
342342
if (i)
343343
*i = *(p);
@@ -3158,8 +3158,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
31583158
/* Ensure that no reject options are present */
31593159
for (i = 1; i < 255; i++) {
31603160
if (has_option_mask(ifo->rejectmask, i) &&
3161-
get_option_uint8(ifp->ctx, &tmp,
3162-
bootp, bootp_len, (uint8_t)i) == 0)
3161+
get_option(ifp->ctx, bootp, bootp_len, (uint8_t)i, NULL))
31633162
{
31643163
LOGDHCP(LOG_WARNING, "reject DHCP");
31653164
return;
@@ -3207,8 +3206,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
32073206
/* Ensure that all required options are present */
32083207
for (i = 1; i < 255; i++) {
32093208
if (has_option_mask(ifo->requiremask, i) &&
3210-
get_option_uint8(ifp->ctx, &tmp,
3211-
bootp, bootp_len, (uint8_t)i) != 0)
3209+
!get_option(ifp->ctx, bootp, bootp_len, (uint8_t)i, NULL))
32123210
{
32133211
/* If we are BOOTP, then ignore the need for serverid.
32143212
* To ignore BOOTP, require dhcp_message_type.

0 commit comments

Comments
 (0)