Skip to content

Commit

Permalink
dhcp: get_option_uint* only accept options with correct len (#357)
Browse files Browse the repository at this point in the history
RFC8925 mentions "The client MUST ignore the IPv6-Only Preferred option
if the length field value is not 4."
  • Loading branch information
taoyl-g authored Sep 5, 2024
1 parent 82e16d1 commit 72a2628
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ get_option_uint32(struct dhcpcd_ctx *ctx,
uint32_t d;

p = get_option(ctx, bootp, bootp_len, option, &len);
if (!p || len < (ssize_t)sizeof(d))
if (!p || len != (ssize_t)sizeof(d))
return -1;
memcpy(&d, p, sizeof(d));
if (i)
Expand All @@ -321,7 +321,7 @@ get_option_uint16(struct dhcpcd_ctx *ctx,
uint16_t d;

p = get_option(ctx, bootp, bootp_len, option, &len);
if (!p || len < (ssize_t)sizeof(d))
if (!p || len != (ssize_t)sizeof(d))
return -1;
memcpy(&d, p, sizeof(d));
if (i)
Expand All @@ -337,7 +337,7 @@ get_option_uint8(struct dhcpcd_ctx *ctx,
size_t len;

p = get_option(ctx, bootp, bootp_len, option, &len);
if (!p || len < (ssize_t)sizeof(*p))
if (!p || len != (ssize_t)sizeof(*p))
return -1;
if (i)
*i = *(p);
Expand Down Expand Up @@ -3158,8 +3158,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
/* Ensure that no reject options are present */
for (i = 1; i < 255; i++) {
if (has_option_mask(ifo->rejectmask, i) &&
get_option_uint8(ifp->ctx, &tmp,
bootp, bootp_len, (uint8_t)i) == 0)
get_option(ifp->ctx, bootp, bootp_len, (uint8_t)i, NULL))
{
LOGDHCP(LOG_WARNING, "reject DHCP");
return;
Expand Down Expand Up @@ -3207,8 +3206,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
/* Ensure that all required options are present */
for (i = 1; i < 255; i++) {
if (has_option_mask(ifo->requiremask, i) &&
get_option_uint8(ifp->ctx, &tmp,
bootp, bootp_len, (uint8_t)i) != 0)
!get_option(ifp->ctx, bootp, bootp_len, (uint8_t)i, NULL))
{
/* If we are BOOTP, then ignore the need for serverid.
* To ignore BOOTP, require dhcp_message_type.
Expand Down

0 comments on commit 72a2628

Please sign in to comment.