From: Roy Marples Date: Thu, 19 Dec 2019 15:36:31 +0000 (+0000) Subject: DHCP: Ensure we have a lease to extract options from. X-Git-Tag: v8.1.3~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5a0f1406bc1d1cfcf0afcd53ab2a737ec8e1c2d;p=thirdparty%2Fdhcpcd.git DHCP: Ensure we have a lease to extract options from. --- diff --git a/src/dhcp.c b/src/dhcp.c index 686aee44..797b3ad4 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -176,6 +176,11 @@ get_option(struct dhcpcd_ctx *ctx, const uint8_t *op; size_t bl; + if (bootp == NULL || bootp_len < DHCP_MIN_LEN) { + errno = EINVAL; + return NULL; + } + /* Check we have the magic cookie */ if (!IS_DHCP(bootp)) { errno = ENOTSUP; @@ -1179,7 +1184,7 @@ read_lease(struct interface *ifp, struct bootp **bootp) * (it should be more, and our read packet enforces this so this * code should not be needed, but of course people could * scribble whatever in the stored lease file. */ - if (bytes < offsetof(struct bootp, vend) + 4) { + if (bytes < DHCP_MIN_LEN) { free(lease); logerrx("%s: %s: truncated lease", ifp->name, __func__); return 0; diff --git a/src/dhcp.h b/src/dhcp.h index 98a8b1e4..2214e6de 100644 --- a/src/dhcp.h +++ b/src/dhcp.h @@ -164,6 +164,8 @@ struct bootp { /* DHCP allows a variable length vendor area */ }; +#define DHCP_MIN_LEN (offsetof(struct bootp, vend) + 4) + struct bootp_pkt { struct ip ip;