From 51e820098a3b105c01af96a19274c9016c579470 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:08:58 +0300 Subject: [PATCH 01/25] if-options: remove duplicate DHO_SUBNETMASK in set_default_allow --- src/if-options.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/if-options.c b/src/if-options.c index 0ec71a43..3a1f62c6 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -635,7 +635,6 @@ set_default_allow(struct if_options *ifo, struct dho_policy_group *pg) struct dho_policy *p = &pg->dhop_allow; if (dho_policy_add(p, DHO_SUBNETMASK) == -1 || - dho_policy_add(p, DHO_SUBNETMASK) == -1 || dho_policy_add(p, DHO_CSR) == -1 || dho_policy_add(p, DHO_ROUTER) == -1 || dho_policy_add(p, DHO_DNSSERVER) == -1 || From 0a5c24fabdeb0765b26d2ff1d3b3b708bd242a0d Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:10:45 +0300 Subject: [PATCH 02/25] if-options: handle NULL ldop and edop safely in parse_option --- src/if-options.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/if-options.c b/src/if-options.c index 3a1f62c6..5a7952e1 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -1910,14 +1910,17 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, dop = &ifo->vivso_override; dop_len = &ifo->vivso_override_len; } - *edop = *ldop = NULL; + if (edop != NULL) + *edop = NULL; + if (ldop != NULL) + *ldop = NULL; /* FALLTHROUGH */ case O_EMBED: if (dop == NULL) { - if (*edop) { + if (edop != NULL && *edop != NULL) { dop = &(*edop)->embopts; dop_len = &(*edop)->embopts_len; - } else if (*ldop) { + } else if (ldop != NULL && *ldop != NULL) { dop = &(*ldop)->embopts; dop_len = &(*ldop)->embopts_len; } else { @@ -1930,7 +1933,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, case O_ENCAP: ARG_REQUIRED; if (dop == NULL) { - if (*ldop == NULL) { + if (ldop == NULL || *ldop == NULL) { logerrx("encap must be after a define"); return -1; } @@ -2185,10 +2188,12 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, case O_DEFINEND: case O_DEFINE6: case O_VENDOPT: - *ldop = ndop; + if (ldop != NULL) + *ldop = ndop; break; case O_ENCAP: - *edop = ndop; + if (edop != NULL) + *edop = ndop; break; } break; @@ -3048,10 +3053,12 @@ add_options(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, { int oi, opt, r; unsigned long long wait_opts; + struct dhcp_opt *ldop, *edop; if (argc == 0) return 1; + ldop = edop = NULL; optind = 0; r = 1; /* Don't apply the command line wait options to each interface, @@ -3062,7 +3069,7 @@ add_options(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, (opt = getopt_long(argc, argv, ctx->options & DHCPCD_PRINT_PIDFILE ? NOERR_IF_OPTS : IF_OPTS, cf_options, &oi)) != -1) { - r = parse_option(ctx, ifname, ifo, opt, optarg, NULL, NULL); + r = parse_option(ctx, ifname, ifo, opt, optarg, &ldop, &edop); if (r != 1) break; } From baa6a9b872509b7e42edf62ba048be9b124970f5 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:11:11 +0300 Subject: [PATCH 03/25] common: fix preprocessor macro typo for GCC version check --- src/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index 577afc4d..36a334a8 100644 --- a/src/common.h +++ b/src/common.h @@ -158,7 +158,7 @@ #define __restrict #elif __STDC_VERSION__ >= 199901L #define __restrict restrict -#elif !(2 < __GNUC__ || (2 == __GNU_C && 95 <= __GNUC_VERSION__)) +#elif !(2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) #define __restrict #endif #endif From 44684d2f33e7d1e062e98d27a030003602612cee Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:11:50 +0300 Subject: [PATCH 04/25] dhcp6: use ia.iaid instead of uninitialized iaid buffer --- src/dhcp6.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/dhcp6.c b/src/dhcp6.c index 8cb87400..7a12f0e8 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -2436,8 +2436,7 @@ dhcp6_findia(struct interface *ifp, struct dhcp6_message *m, size_t l, int i, e, error; size_t j; uint16_t nl; - uint8_t iaid[4]; - char buf[sizeof(iaid) * 3]; + char buf[sizeof(ia.iaid) * 3]; struct ipv6_addr *ap; struct if_ia *ifia; @@ -2516,7 +2515,7 @@ dhcp6_findia(struct interface *ifp, struct dhcp6_message *m, size_t l, if (ia.t2 > 0 && ia.t1 > ia.t2) { logwarnx("%s: IAID %s T1(%d) > T2(%d) from %s", ifp->name, - hwaddr_ntoa(iaid, sizeof(iaid), buf, + hwaddr_ntoa(ia.iaid, sizeof(ia.iaid), buf, sizeof(buf)), ia.t1, ia.t2, sfrom); continue; From 201c1b23c8fafa3a32f5ff0993a307f1bcd2aa6c Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:26:10 +0300 Subject: [PATCH 05/25] ipv4: remove redundant pointer check in IPV4_MASK1_EQ and IPV4_BRD1_EQ --- src/dhcpcd.c | 2 +- src/ipv4.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 3ba0eecf..359b101a 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -1348,7 +1348,7 @@ dhcpcd_handlehwaddr(struct interface *ifp, uint16_t hwtype, const void *hwaddr, hwaddr_ntoa(hwaddr, hwlen, buf, sizeof(buf))); } ifp->hwlen = hwlen; - if (hwaddr != NULL) + if (hwlen != 0) memcpy(ifp->hwaddr, hwaddr, hwlen); } diff --git a/src/ipv4.h b/src/ipv4.h index 90c9110c..d6535530 100644 --- a/src/ipv4.h +++ b/src/ipv4.h @@ -111,9 +111,9 @@ TAILQ_HEAD(ipv4_addrhead, ipv4_addr); #define IPV4_AF_NEW (1U << 1) #define IPV4_ADDR_EQ(a1, a2) ((a1) && (a1)->addr.s_addr == (a2)->addr.s_addr) -#define IPV4_MASK1_EQ(a1, a2) ((a1) && (a1)->mask.s_addr == (a2)->mask.s_addr) +#define IPV4_MASK1_EQ(a1, a2) ((a1)->mask.s_addr == (a2)->mask.s_addr) #define IPV4_MASK_EQ(a1, a2) (IPV4_ADDR_EQ(a1, a2) && IPV4_MASK1_EQ(a1, a2)) -#define IPV4_BRD1_EQ(a1, a2) ((a1) && (a1)->brd.s_addr == (a2)->brd.s_addr) +#define IPV4_BRD1_EQ(a1, a2) ((a1)->brd.s_addr == (a2)->brd.s_addr) #define IPV4_BRD_EQ(a1, a2) (IPV4_MASK_EQ(a1, a2) && IPV4_BRD1_EQ(a1, a2)) struct ipv4_state { From 6aed0e6596ec72ba6ac01553c45734057cf8e3c4 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:26:36 +0300 Subject: [PATCH 06/25] ipv6: guard against NULL router pointer in inet6_makeprefix --- src/ipv6.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ipv6.c b/src/ipv6.c index 80ee4ad3..de6df241 100644 --- a/src/ipv6.c +++ b/src/ipv6.c @@ -165,13 +165,11 @@ ipv6_readsecret(struct dhcpcd_ctx *ctx) * RFC7217 section 5.1 states the key SHOULD be at least 128 bits. * To attempt and future proof ourselves, we'll generate a key of * 512 bits (64 bytes). */ - if (ctx->secret_len < 64) { - if ((ctx->secret = malloc(64)) == NULL) { - logerr(__func__); - return -1; - } - ctx->secret_len = 64; + if ((ctx->secret = malloc(64)) == NULL) { + logerr(__func__); + return -1; } + ctx->secret_len = 64; p = ctx->secret; for (len = 0; len < 512 / NBBY; len += sizeof(r)) { r = arc4random(); @@ -2229,7 +2227,7 @@ inet6_makeprefix(struct interface *ifp, const struct ra *rap, #ifndef __linux__ sa_in6_init(rt->rt_gateway, &in6addr_loopback); #endif - } else if (!(addr->flags & IPV6_AF_ONLINK)) + } else if (rap != NULL && !(addr->flags & IPV6_AF_ONLINK)) sa_in6_init(rt->rt_gateway, &rap->from); else rt->rt_gateway->sa_family = AF_UNSPEC; From 1febd6e44c5f81caa09202b9c563ea95add2fb04 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:27:04 +0300 Subject: [PATCH 07/25] if-linux: check ctx for NULL before checking sequence in if_getnetlink --- src/if-linux.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/if-linux.c b/src/if-linux.c index c5739cb0..030ce3d2 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -774,7 +774,8 @@ if_getnetlink(struct dhcpcd_ctx *ctx, struct iovec *iov, int fd, int flags, } if (cb == NULL) continue; - if (nlm->nlmsg_seq != (uint32_t)ctx->seq && fd != ctx->link_fd) + if (ctx != NULL && + nlm->nlmsg_seq != (uint32_t)ctx->seq && fd != ctx->link_fd) logwarnx("%s: received sequence %u, expecting %d", __func__, nlm->nlmsg_seq, ctx->seq); else From 71ee976d5fd829edfbaa483ae1550f533a51b358 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:27:48 +0300 Subject: [PATCH 08/25] ipv4: allow CIDR /0 in inet_cidrtoaddr --- src/dhcp-common.c | 4 ++-- src/ipv4.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dhcp-common.c b/src/dhcp-common.c index fd090f05..bfa3f578 100644 --- a/src/dhcp-common.c +++ b/src/dhcp-common.c @@ -194,12 +194,12 @@ dhcp_vendor(char *str, size_t len) p = str; l = snprintf(p, len, "%s-%s:%s-%s:%s", PACKAGE, VERSION, utn.sysname, utn.release, utn.machine); - if (l == -1 || (size_t)(l + 1) > len) + if (l == -1 || (size_t)l >= len) return -1; p += l; len -= (size_t)l; l = if_machinearch(p + 1, len - 1); - if (l == -1 || (size_t)(l + 1) > len) + if (l == -1 || (size_t)l >= len) return -1; if (l != 0) { *p = ':'; diff --git a/src/ipv4.c b/src/ipv4.c index 2d2b8008..fe8fb9c6 100644 --- a/src/ipv4.c +++ b/src/ipv4.c @@ -84,7 +84,7 @@ inet_cidrtoaddr(int cidr, struct in_addr *addr) { int ocets; - if (cidr < 1 || cidr > 32) { + if (cidr < 0 || cidr > 32) { errno = EINVAL; return -1; } From b0bacf9d9854f20868e2fe4c0b8173216588375a Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:50:28 +0300 Subject: [PATCH 09/25] arp: initialize falen to prevent reading uninitialized memory --- src/arp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arp.c b/src/arp.c index c33d3a79..a702cfb3 100644 --- a/src/arp.c +++ b/src/arp.c @@ -231,7 +231,7 @@ void arp_packet(struct interface *ifp, uint8_t *data, size_t len, unsigned int bpf_flags) { - size_t fl = bpf_frame_header_len(ifp), falen; + size_t fl = bpf_frame_header_len(ifp), falen = 0; struct arphdr ar; struct arp_msg arm; const struct iarp_state *state; From b8949c46325bdaf446a4a18fbc663fee6fbde343 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:50:57 +0300 Subject: [PATCH 10/25] ipv4ll: prevent passing NULL prefix to efprintf --- src/ipv4ll.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ipv4ll.c b/src/ipv4ll.c index 64aa3c4f..aeed186b 100644 --- a/src/ipv4ll.c +++ b/src/ipv4ll.c @@ -141,6 +141,7 @@ ssize_t ipv4ll_env(FILE *fp, const char *prefix, const struct interface *ifp) { const struct ipv4ll_state *state; + const char *pfx = prefix == NULL ? "" : prefix; const char *pf = prefix == NULL ? "" : "_"; struct in_addr netnum; @@ -149,20 +150,20 @@ ipv4ll_env(FILE *fp, const char *prefix, const struct interface *ifp) return 0; /* Emulate a DHCP environment */ - if (efprintf(fp, "%s%sip_address=%s", prefix, pf, + if (efprintf(fp, "%s%sip_address=%s", pfx, pf, inet_ntoa(state->addr->addr)) == -1) return -1; - if (efprintf(fp, "%s%ssubnet_mask=%s", prefix, pf, + if (efprintf(fp, "%s%ssubnet_mask=%s", pfx, pf, inet_ntoa(state->addr->mask)) == -1) return -1; - if (efprintf(fp, "%s%ssubnet_cidr=%d", prefix, pf, + if (efprintf(fp, "%s%ssubnet_cidr=%d", pfx, pf, inet_ntocidr(state->addr->mask)) == -1) return -1; - if (efprintf(fp, "%s%sbroadcast_address=%s", prefix, pf, + if (efprintf(fp, "%s%sbroadcast_address=%s", pfx, pf, inet_ntoa(state->addr->brd)) == -1) return -1; netnum.s_addr = state->addr->addr.s_addr & state->addr->mask.s_addr; - if (efprintf(fp, "%s%snetwork_number=%s", prefix, pf, + if (efprintf(fp, "%s%snetwork_number=%s", pfx, pf, inet_ntoa(netnum)) == -1) return -1; return 5; From 7e75c5ea03aa6e987775a6b375d504a18025a1cd Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:51:16 +0300 Subject: [PATCH 11/25] dhcpcd: handle NULL ifname safely in single-interface check --- src/dhcpcd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 359b101a..63d86ac8 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -2361,7 +2361,10 @@ main(int argc, char **argv, char **envp) ifname = *ctx.ifv; if (ifname == NULL || strlen(ifname) > IF_NAMESIZE) { errno = ifname == NULL ? EINVAL : E2BIG; - logerr("%s: ", ifname); + if (ifname != NULL) + logerr("%s", ifname); + else + logerr("interface name"); goto exit_failure; } /* Allow a dhcpcd interface per address family */ From c6c9fc6f84d2817646665c60db8559a81509443a Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:52:54 +0300 Subject: [PATCH 12/25] dhcp: prevent uint8_t overflow on clientid length and remove dead nolease check --- src/dhcp.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/dhcp.c b/src/dhcp.c index c6267d78..b5d9a113 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -3161,9 +3161,6 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, return; } - if (!ifp->active) - return; - i = whitelisted_ip(ifp->options, from->s_addr); switch (i) { case WHTLST_NOMATCH: @@ -4006,6 +4003,10 @@ dhcp_init(struct interface *ifp) ifp->ctx->duid_len); } else { make_clientid: + if (ifp->hwlen >= UINT8_MAX) { + errno = ENOBUFS; + goto eexit; + } len = (uint8_t)(ifp->hwlen + 1); state->clientid = malloc((size_t)len + 1); if (state->clientid == NULL) @@ -4043,7 +4044,6 @@ dhcp_start1(void *arg) struct if_options *ifo = ifp->options; struct dhcp_state *state; uint32_t l; - int nolease; if (!(ifo->options & DHCPCD_IPV4)) return; @@ -4102,9 +4102,7 @@ dhcp_start1(void *arg) return; } - /* We don't want to read the old lease if we NAK an old test */ - nolease = state->offer && ifp->ctx->options & DHCPCD_TEST; - if (!nolease && ifo->options & DHCPCD_DHCP) { + if (ifo->options & DHCPCD_DHCP) { state->offer_len = read_lease(ifp, &state->offer); /* Check the saved lease matches the type we want */ if (state->offer) { From 2746e15aa2c3cf829ea809b1f6e115449e5976b5 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:53:54 +0300 Subject: [PATCH 13/25] dhcp-common: clean up unreachable break, duplicate assignment, and redundant check --- src/dhcp-common.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/dhcp-common.c b/src/dhcp-common.c index bfa3f578..a2108332 100644 --- a/src/dhcp-common.c +++ b/src/dhcp-common.c @@ -443,8 +443,6 @@ encode_rfc1035(const char *src, uint8_t *dst) len = 1; has_dot = 0; for (; *src; src++) { - if (*src == '\0') - break; if (*src == '.') { /* Skip the trailing . */ if (src[1] == '\0') @@ -489,7 +487,6 @@ decode_rfc1035(char *out, size_t len, const uint8_t *p, size_t pl) o_len = 0; start = out; start_len = len; - q = p; e = p + pl; while (q < e) { r = NULL; @@ -1208,7 +1205,7 @@ dhcp_readfile(struct dhcpcd_ctx *ctx, const char *file, void **data, } #ifdef PRIVSEP - if (file != NULL && ctx->options & DHCPCD_PRIVSEP && + if (ctx->options & DHCPCD_PRIVSEP && !(ctx->options & DHCPCD_PRIVSEPROOT)) return ps_root_readfile(ctx, file, data, len); #else From f3faa50072fbd276c1837977353fb44f084b67e4 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:54:52 +0300 Subject: [PATCH 14/25] if-linux: prevent signed integer overflow when incrementing netlink sequence --- src/if-linux.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/if-linux.c b/src/if-linux.c index 030ce3d2..504a57b5 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -1327,9 +1328,9 @@ if_sendnetlink(struct dhcpcd_ctx *ctx, int protocol, struct nlmsghdr *hdr, /* Request a reply */ hdr->nlmsg_flags |= NLM_F_ACK; - hdr->nlmsg_seq = (uint32_t)++ctx->seq; - if ((unsigned int)ctx->seq > UINT32_MAX) + if (ctx->seq >= INT_MAX) ctx->seq = 0; + hdr->nlmsg_seq = (uint32_t)++ctx->seq; #ifdef PRIVSEP if (ctx->options & DHCPCD_PRIVSEP && if_netlinkpriv(protocol, hdr)) From 5b4c29a6cf1134e81083f441f6777b1a60038379 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:55:33 +0300 Subject: [PATCH 15/25] privsep-root: remove dead pid check and redundant NULL check --- src/privsep-root.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/privsep-root.c b/src/privsep-root.c index 78ee783d..311af617 100644 --- a/src/privsep-root.c +++ b/src/privsep-root.c @@ -498,7 +498,7 @@ ps_root_recvmsgcb(void *arg, struct ps_msghdr *psm, struct msghdr *msg) return 0; } - if (psm->ps_cmd & PS_STOP && psp == NULL) + if (psm->ps_cmd & PS_STOP) return 0; switch (cmd) { @@ -928,8 +928,7 @@ ps_root_start(struct dhcpcd_ctx *ctx) ctx->ps_data_fd = datafd[1]; close(datafd[0]); return 0; - } else if (pid == -1) - return -1; + } logsetfd(logfd[0]); close(logfd[1]); From 64a0c03044c714d54dad5b4620e2e8e11105d973 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:56:16 +0300 Subject: [PATCH 16/25] dhcp6: remove redundant conditions in delegateaddr and sendmessage --- src/dhcp6.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dhcp6.c b/src/dhcp6.c index 7a12f0e8..caacd4b9 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -633,7 +633,7 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp, int bits; sla_max = ia->sla_max; - if (sla_max == 0 && (sla == NULL || !sla->sla_set)) { + if (sla_max == 0 && !sla->sla_set) { const struct interface *ifi; TAILQ_FOREACH(ifi, ifp->ctx->ifaces, next) { @@ -1462,7 +1462,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *)) state->RT = RT; if (state->MRC == 0 || state->RTC <= state->MRC) eloop_timeout_add_msec(ctx->eloop, RT, callback, ifp); - else if (state->MRC != 0 && state->MRCcallback) + else if (state->MRCcallback) eloop_timeout_add_msec(ctx->eloop, RT, state->MRCcallback, ifp); else From 8c4b12bee1c76c5065cb785e725fec23bba69d43 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 17:56:37 +0300 Subject: [PATCH 17/25] ipv6nd: remove redundant expired check in router expiry loop --- src/ipv6nd.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ipv6nd.c b/src/ipv6nd.c index 5f881915..1759aaea 100644 --- a/src/ipv6nd.c +++ b/src/ipv6nd.c @@ -1796,12 +1796,10 @@ ipv6nd_expirera(void *arg) ltime = lifetime_left(rap->lifetime, &rap->acquired, &now); if (ltime == 0 || rap->doexpire) { - if (!rap->expired) { - logwarnx("%s: %s: router expired", - ifp->name, rap->sfrom); - rap->lifetime = 0; - expired = true; - } + logwarnx("%s: %s: router expired", + ifp->name, rap->sfrom); + rap->lifetime = 0; + expired = true; } else { valid = true; if (next == 0 || ltime < next) From 21cfc3a12222a9b5bb47780974fd0744e7051468 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 18:06:42 +0300 Subject: [PATCH 18/25] if-options: fix setting auth algorithm instead of protocol for token --- src/if-options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/if-options.c b/src/if-options.c index 5a7952e1..692f2222 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -2276,7 +2276,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, if (arg == NULL) { ifo->auth.options |= DHCPCD_AUTH_SEND; if (ifo->auth.protocol == AUTH_PROTO_TOKEN) - ifo->auth.protocol = AUTH_ALG_NONE; + ifo->auth.algorithm = AUTH_ALG_NONE; else ifo->auth.algorithm = AUTH_ALG_HMAC_MD5; ifo->auth.rdm = AUTH_RDM_MONOTONIC; From d439b3d73457269e4fb64da41aa20a0c67e86d29 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 18:07:04 +0300 Subject: [PATCH 19/25] ipv4: avoid use-after-free of ap in ipv4_deleteaddr --- src/ipv4.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ipv4.c b/src/ipv4.c index fe8fb9c6..d41dc4f0 100644 --- a/src/ipv4.c +++ b/src/ipv4.c @@ -544,13 +544,12 @@ ipv4_deladdr(struct ipv4_addr *addr, int keeparp) struct dhcp_state *dstate; dstate = D_STATE(ap->iface); - TAILQ_REMOVE(&state->addrs, ap, next); - free(ap); - if (dstate && dstate->addr == ap) { dstate->added = 0; dstate->addr = NULL; } + TAILQ_REMOVE(&state->addrs, ap, next); + free(ap); break; } } From 9e9d353bdebb29b34a27b145ff607ea1e9258b22 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 18:07:53 +0300 Subject: [PATCH 20/25] ipv6: check for NULL state returned by ipv6_getstate --- src/ipv6.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ipv6.c b/src/ipv6.c index de6df241..4ca45986 100644 --- a/src/ipv6.c +++ b/src/ipv6.c @@ -815,6 +815,8 @@ ipv6_addaddr1(struct ipv6_addr *ia, struct timespec *now) if (iaf == NULL) { struct ipv6_state *state = ipv6_getstate(ifp); + if (state == NULL) + return -1; if ((iaf = malloc(sizeof(*iaf))) == NULL) { logerr(__func__); return 0; /* Well, we did add the address */ @@ -1396,6 +1398,8 @@ ipv6_addlinklocalcallback(struct interface *ifp, void (*callback)(void *), struct ll_callback *cb; state = ipv6_getstate(ifp); + if (state == NULL) + return -1; TAILQ_FOREACH(cb, &state->ll_callbacks, next) { if (cb->callback == callback && cb->arg == arg) return 0; From 7f2075a79c25b4ef0a7447e6f852906da5948987 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 18:08:23 +0300 Subject: [PATCH 21/25] dhcpcd: return early if ifp->options is NULL in dhcpcd_handlecarrier --- src/dhcpcd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 63d86ac8..0c184509 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -785,10 +785,9 @@ dhcpcd_handlecarrier(struct interface *ifp, int carrier, unsigned int flags) * global context if we are stopping or not. * This allows an active interface to stop even if dhcpcd is not. */ - if (ifp->options != NULL) { - if (ifp->options->options & DHCPCD_STOPPING) - return; - } else if (ifp->ctx->options & DHCPCD_EXITING) + if (ifp->options == NULL || + ifp->options->options & DHCPCD_STOPPING || + ifp->ctx->options & DHCPCD_EXITING) return; if (!if_is_link_up(ifp)) { From 953b57678d08b2e89d0d35c571e1f3515c037d96 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 18:08:50 +0300 Subject: [PATCH 22/25] dhcp: remove duplicate *bootp = NULL assignment in read_lease --- src/dhcp.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dhcp.c b/src/dhcp.c index b5d9a113..534f2ce5 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -1258,7 +1258,6 @@ read_lease(struct interface *ifp, struct bootp **bootp) logdebugx("reading standard input"); else logdebugx("%s: reading lease: %s", ifp->name, state->leasefile); - *bootp = NULL; sbytes = dhcp_readfile(ifp->ctx, state->leasefile, (void **)bootp, NULL); if (sbytes == -1) { From b136abf9010f6fa500e3c9692cda76bc20001a7a Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 18:09:08 +0300 Subject: [PATCH 23/25] ipv4: clarify operator precedence in inet_cidrtoaddr netmask calculation --- src/ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipv4.c b/src/ipv4.c index d41dc4f0..1d0a1f4c 100644 --- a/src/ipv4.c +++ b/src/ipv4.c @@ -94,7 +94,7 @@ inet_cidrtoaddr(int cidr, struct in_addr *addr) if (ocets > 0) { memset(&addr->s_addr, 255, (size_t)ocets - 1); memset((unsigned char *)&addr->s_addr + (ocets - 1), - (256 - (1 << (32 - cidr) % NBBY)), 1); + (256 - (1 << ((32 - cidr) % NBBY))), 1); } return 0; From 5808770c9007881b6d2388063f2beb7db6a57a9c Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 18:09:44 +0300 Subject: [PATCH 24/25] duid: parenthesize DUID_LEN and DUID_STRLEN to fix buffer size calculation --- src/duid.c | 2 +- src/duid.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/duid.c b/src/duid.c index d3cba7e6..a9bae413 100644 --- a/src/duid.c +++ b/src/duid.c @@ -152,7 +152,7 @@ duid_make(void *d, const struct interface *ifp, uint16_t type) return (size_t)(p - (uint8_t *)d); } -#define DUID_STRLEN DUID_LEN * 3 +#define DUID_STRLEN (DUID_LEN * 3) static size_t duid_get(struct dhcpcd_ctx *ctx, const struct interface *ifp) { diff --git a/src/duid.h b/src/duid.h index 294e30db..c63381e0 100644 --- a/src/duid.h +++ b/src/duid.h @@ -28,7 +28,7 @@ #ifndef DUID_H #define DUID_H -#define DUID_LEN 128 + 2 +#define DUID_LEN (128 + 2) #define DUID_DEFAULT 0 #define DUID_LLT 1 #define DUID_LL 3 From 83de2d15b25f3170b9ccfab9f24adca1e5112039 Mon Sep 17 00:00:00 2001 From: devuan Date: Thu, 19 Nov 2026 18:12:58 +0300 Subject: [PATCH 25/25] macros: parenthesize expressions and parameters to prevent operator precedence issues --- src/bpf.c | 14 +++--- src/if-options.h | 128 +++++++++++++++++++++++------------------------ src/if.h | 10 ++-- src/ipv4ll.h | 2 +- src/ipv6nd.c | 12 ++--- src/privsep.h | 2 +- 6 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/bpf.c b/src/bpf.c index 83965c1e..2eb7e422 100644 --- a/src/bpf.c +++ b/src/bpf.c @@ -294,11 +294,11 @@ static const struct bpf_insn bpf_arp_filter[] = { /* One address is two checks of two statements. */ #define BPF_NADDRS 1 -#define BPF_ARP_ADDRS_LEN 5 + ((BPF_NADDRS * 2) * 2) +#define BPF_ARP_ADDRS_LEN (5 + ((BPF_NADDRS * 2) * 2)) -#define BPF_ARP_LEN \ - BPF_ARP_ETHER_LEN + BPF_ARP_FILTER_LEN + BPF_CMP_HWADDR_LEN + \ - BPF_ARP_ADDRS_LEN +#define BPF_ARP_LEN \ + (BPF_ARP_ETHER_LEN + BPF_ARP_FILTER_LEN + BPF_CMP_HWADDR_LEN + \ + BPF_ARP_ADDRS_LEN) static int bpf_arp_rw(const struct bpf *bpf, const struct in_addr *ia, bool recv) @@ -447,9 +447,9 @@ static const struct bpf_insn bpf_bootp_write[] = { #define BPF_BOOTP_CHADDR_LEN ((BOOTP_CHADDR_LEN / 4) * 3) #define BPF_BOOTP_XID_LEN 4 /* BOUND check is 4 instructions */ -#define BPF_BOOTP_LEN \ - BPF_BOOTP_ETHER_LEN + BPF_BOOTP_BASE_LEN + BPF_BOOTP_READ_LEN + \ - BPF_BOOTP_XID_LEN + BPF_BOOTP_CHADDR_LEN + 4 +#define BPF_BOOTP_LEN \ + (BPF_BOOTP_ETHER_LEN + BPF_BOOTP_BASE_LEN + BPF_BOOTP_READ_LEN + \ + BPF_BOOTP_XID_LEN + BPF_BOOTP_CHADDR_LEN + 4) static int bpf_bootp_rw(const struct bpf *bpf, bool read) diff --git a/src/if-options.h b/src/if-options.h index 0158b9ae..5e7f6978 100644 --- a/src/if-options.h +++ b/src/if-options.h @@ -141,70 +141,70 @@ /* These options only make sense in the config file, so don't use any valid short options for them */ -#define O_BASE MAX('z', 'Z') + 1 -#define O_ARPING O_BASE + 1 -#define O_FALLBACK O_BASE + 2 -#define O_DESTINATION O_BASE + 3 -#define O_IPV6RS O_BASE + 4 -#define O_NOIPV6RS O_BASE + 5 -#define O_IPV6RA_FORK O_BASE + 6 -#define O_LINK_RCVBUF O_BASE + 7 -#define O_ANONYMOUS O_BASE + 8 -#define O_NOALIAS O_BASE + 9 -#define O_IA_NA O_BASE + 10 -#define O_IA_TA O_BASE + 11 -#define O_IA_PD O_BASE + 12 -#define O_HOSTNAME_SHORT O_BASE + 13 -#define O_DEV O_BASE + 14 -#define O_NODEV O_BASE + 15 -#define O_NOIPV4 O_BASE + 16 -#define O_NOIPV6 O_BASE + 17 -#define O_IAID O_BASE + 18 -#define O_DEFINE O_BASE + 19 -#define O_DEFINE6 O_BASE + 20 -#define O_EMBED O_BASE + 21 -#define O_ENCAP O_BASE + 22 -#define O_VENDOPT O_BASE + 23 -#define O_VENDCLASS O_BASE + 24 -#define O_AUTHPROTOCOL O_BASE + 25 -#define O_AUTHTOKEN O_BASE + 26 -#define O_AUTHNOTREQUIRED O_BASE + 27 -#define O_NODHCP O_BASE + 28 -#define O_NODHCP6 O_BASE + 29 -#define O_DHCP O_BASE + 30 -#define O_DHCP6 O_BASE + 31 -#define O_IPV4 O_BASE + 32 -#define O_IPV6 O_BASE + 33 -#define O_CONTROLGRP O_BASE + 34 -#define O_SLAAC O_BASE + 35 -#define O_GATEWAY O_BASE + 36 -#define O_NOUP O_BASE + 37 -#define O_IPV6RA_AUTOCONF O_BASE + 38 -#define O_IPV6RA_NOAUTOCONF O_BASE + 39 -#define O_REJECT O_BASE + 40 -#define O_BOOTP O_BASE + 42 -#define O_DEFINEND O_BASE + 43 -#define O_NODELAY O_BASE + 44 -#define O_INFORM6 O_BASE + 45 -#define O_LASTLEASE_EXTEND O_BASE + 46 -#define O_INACTIVE O_BASE + 47 -#define O_MUDURL O_BASE + 48 -#define O_MSUSERCLASS O_BASE + 49 -#define O_CONFIGURE O_BASE + 50 -#define O_NOCONFIGURE O_BASE + 51 -#define O_RANDOMISE_HWADDR O_BASE + 52 -#define O_ARP_PERSISTDEFENCE O_BASE + 53 -#define O_REQUEST_TIME O_BASE + 54 -#define O_FALLBACK_TIME O_BASE + 55 -#define O_IPV4LL_TIME O_BASE + 56 -#define O_VSIO O_BASE + 57 -#define O_VSIO6 O_BASE + 58 -#define O_NOSYSLOG O_BASE + 59 -#define O_INITIAL_INTERVAL O_BASE + 60 -#define O_BACKOFF_CUTOFF O_BASE + 61 -#define O_BACKOFF_JITTER O_BASE + 62 -#define O_ALLOW O_BASE + 63 -#define O_READGRP O_BASE + 64 +#define O_BASE (MAX('z', 'Z') + 1) +#define O_ARPING (O_BASE + 1) +#define O_FALLBACK (O_BASE + 2) +#define O_DESTINATION (O_BASE + 3) +#define O_IPV6RS (O_BASE + 4) +#define O_NOIPV6RS (O_BASE + 5) +#define O_IPV6RA_FORK (O_BASE + 6) +#define O_LINK_RCVBUF (O_BASE + 7) +#define O_ANONYMOUS (O_BASE + 8) +#define O_NOALIAS (O_BASE + 9) +#define O_IA_NA (O_BASE + 10) +#define O_IA_TA (O_BASE + 11) +#define O_IA_PD (O_BASE + 12) +#define O_HOSTNAME_SHORT (O_BASE + 13) +#define O_DEV (O_BASE + 14) +#define O_NODEV (O_BASE + 15) +#define O_NOIPV4 (O_BASE + 16) +#define O_NOIPV6 (O_BASE + 17) +#define O_IAID (O_BASE + 18) +#define O_DEFINE (O_BASE + 19) +#define O_DEFINE6 (O_BASE + 20) +#define O_EMBED (O_BASE + 21) +#define O_ENCAP (O_BASE + 22) +#define O_VENDOPT (O_BASE + 23) +#define O_VENDCLASS (O_BASE + 24) +#define O_AUTHPROTOCOL (O_BASE + 25) +#define O_AUTHTOKEN (O_BASE + 26) +#define O_AUTHNOTREQUIRED (O_BASE + 27) +#define O_NODHCP (O_BASE + 28) +#define O_NODHCP6 (O_BASE + 29) +#define O_DHCP (O_BASE + 30) +#define O_DHCP6 (O_BASE + 31) +#define O_IPV4 (O_BASE + 32) +#define O_IPV6 (O_BASE + 33) +#define O_CONTROLGRP (O_BASE + 34) +#define O_SLAAC (O_BASE + 35) +#define O_GATEWAY (O_BASE + 36) +#define O_NOUP (O_BASE + 37) +#define O_IPV6RA_AUTOCONF (O_BASE + 38) +#define O_IPV6RA_NOAUTOCONF (O_BASE + 39) +#define O_REJECT (O_BASE + 40) +#define O_BOOTP (O_BASE + 42) +#define O_DEFINEND (O_BASE + 43) +#define O_NODELAY (O_BASE + 44) +#define O_INFORM6 (O_BASE + 45) +#define O_LASTLEASE_EXTEND (O_BASE + 46) +#define O_INACTIVE (O_BASE + 47) +#define O_MUDURL (O_BASE + 48) +#define O_MSUSERCLASS (O_BASE + 49) +#define O_CONFIGURE (O_BASE + 50) +#define O_NOCONFIGURE (O_BASE + 51) +#define O_RANDOMISE_HWADDR (O_BASE + 52) +#define O_ARP_PERSISTDEFENCE (O_BASE + 53) +#define O_REQUEST_TIME (O_BASE + 54) +#define O_FALLBACK_TIME (O_BASE + 55) +#define O_IPV4LL_TIME (O_BASE + 56) +#define O_VSIO (O_BASE + 57) +#define O_VSIO6 (O_BASE + 58) +#define O_NOSYSLOG (O_BASE + 59) +#define O_INITIAL_INTERVAL (O_BASE + 60) +#define O_BACKOFF_CUTOFF (O_BASE + 61) +#define O_BACKOFF_JITTER (O_BASE + 62) +#define O_ALLOW (O_BASE + 63) +#define O_READGRP (O_BASE + 64) extern const struct option cf_options[]; diff --git a/src/if.h b/src/if.h index 6b64b6c9..9d1f0ff7 100644 --- a/src/if.h +++ b/src/if.h @@ -91,7 +91,7 @@ typedef unsigned long ioctl_request_t; #define FRAMEHDRLEN_MAX 14 /* only ethernet support */ #define FRAMELEN_MAX (FRAMEHDRLEN_MAX + 9216) -#define UDPLEN_MAX 64 * 1024 +#define UDPLEN_MAX (64 * 1024) /* Work out if we have a private address or not * 10/8 @@ -99,10 +99,10 @@ typedef unsigned long ioctl_request_t; * 192.168/16 */ #ifndef IN_PRIVATE -#define IN_PRIVATE(addr) \ - (((addr & IN_CLASSA_NET) == 0x0a000000) || \ - ((addr & 0xfff00000) == 0xac100000) || \ - ((addr & IN_CLASSB_NET) == 0xc0a80000)) +#define IN_PRIVATE(addr) \ + ((((addr) & IN_CLASSA_NET) == 0x0a000000) || \ + (((addr) & 0xfff00000) == 0xac100000) || \ + (((addr) & IN_CLASSB_NET) == 0xc0a80000)) #endif #ifndef CLLADDR diff --git a/src/ipv4ll.h b/src/ipv4ll.h index 016cca5d..1c6d3107 100644 --- a/src/ipv4ll.h +++ b/src/ipv4ll.h @@ -34,7 +34,7 @@ #define LINKLOCAL_BCAST (LINKLOCAL_ADDR | ~LINKLOCAL_MASK) #ifndef IN_LINKLOCAL -#define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR) +#define IN_LINKLOCAL(addr) (((addr) & IN_CLASSB_NET) == LINKLOCAL_ADDR) #endif #ifdef IPV4LL diff --git a/src/ipv6nd.c b/src/ipv6nd.c index 1759aaea..7bcf1ba4 100644 --- a/src/ipv6nd.c +++ b/src/ipv6nd.c @@ -85,7 +85,7 @@ struct nd_opt_ri { /* Route Information option RFC4191 */ struct in6_addr nd_opt_ri_prefix; }; __CTASSERT(sizeof(struct nd_opt_ri) == 24); -#define OPT_RI_FLAG_PREFERENCE(flags) ((flags & 0x18) >> 3) +#define OPT_RI_FLAG_PREFERENCE(flags) (((flags) & 0x18) >> 3) #endif #ifndef ND_OPT_RDNSS @@ -113,7 +113,7 @@ __CTASSERT(sizeof(struct nd_opt_dnssl) == 8); #endif /* Impossible options, so we can easily add extras */ -#define _ND_OPT_PREFIX_ADDR 255 + 1 +#define _ND_OPT_PREFIX_ADDR (255 + 1) /* Minimal IPv6 MTU */ #ifndef IPV6_MMTU @@ -132,10 +132,10 @@ __CTASSERT(sizeof(struct nd_opt_dnssl) == 8); 5 /* Remember 5 expired routers to avoid \ logspam. */ -#define MIN_RANDOM_FACTOR 500 /* millisecs */ -#define MAX_RANDOM_FACTOR 1500 /* millisecs */ -#define MIN_RANDOM_FACTOR_U MIN_RANDOM_FACTOR * 1000 /* usecs */ -#define MAX_RANDOM_FACTOR_U MAX_RANDOM_FACTOR * 1000 /* usecs */ +#define MIN_RANDOM_FACTOR 500 /* millisecs */ +#define MAX_RANDOM_FACTOR 1500 /* millisecs */ +#define MIN_RANDOM_FACTOR_U (MIN_RANDOM_FACTOR * 1000) /* usecs */ +#define MAX_RANDOM_FACTOR_U (MAX_RANDOM_FACTOR * 1000) /* usecs */ #if BYTE_ORDER == BIG_ENDIAN #define IPV6_ADDR_INT32_ONE 1 diff --git a/src/privsep.h b/src/privsep.h index 7fe4d1f2..050059ea 100644 --- a/src/privsep.h +++ b/src/privsep.h @@ -92,7 +92,7 @@ #define PS_START 0x4000 #define PS_STOP 0x8000 -#define PSP_NAMESIZE 16 + INET_MAX_ADDRSTRLEN +#define PSP_NAMESIZE (16 + INET_MAX_ADDRSTRLEN) /* Handy macro to work out if in the privsep engine or not. */ #define IN_PRIVSEP(ctx) ((ctx)->options & DHCPCD_PRIVSEP)