From 7d58e5dee570494b34e03b7f739cd12bdd6fb3b1 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Fri, 4 Dec 2026 20:51:21 +0000 Subject: [PATCH] Fix possible infinite loop to dhcpv6 tag-handling. It was possible for the same --dhcp-vendorclass or --dhcp-userclass option to match more than once and thus create a loop in the linked-list used to respresent the set of active tags, and put the code that read that into an infinite loop. Code to avoid this was in place, but the check got missed in a couple of places. Thanks to Dickson Wu for spotting this. --- src/rfc3315.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rfc3315.c b/src/rfc3315.c index 690e2f6..ae9f6d3 100644 --- a/src/rfc3315.c +++ b/src/rfc3315.c @@ -90,7 +90,7 @@ unsigned short dhcp6_reply(struct dhcp_context *context, int multicast_dest, int /* Mark these so we only match each at most once, to avoid tangled linked lists */ for (vendor = daemon->dhcp_vendors; vendor; vendor = vendor->next) vendor->netid.next = &vendor->netid; - + reset_counter(); state.context = context; state.interface = interface; @@ -224,7 +224,7 @@ static int dhcp6_maybe_relay(struct state *state, unsigned char *inbuff, size_t if ((opt = opt6_find(opts, end, mopt, 1)) && vendor->len == opt6_len(opt) && memcmp(vendor->data, opt6_ptr(opt, 0), vendor->len) == 0 && - vendor->netid.next != &vendor->netid) + vendor->netid.next == &vendor->netid) { vendor->netid.next = state->tags; state->tags = &vendor->netid; @@ -399,7 +399,8 @@ static int dhcp6_no_relay(struct state *state, int msg_type, unsigned char *inbu continue; /* matching enterprise, no string match. */ - if (vendor->enterprise != 0 && vendor->len == 0) + if (vendor->enterprise != 0 && vendor->len == 0 && + vendor->netid.next == &vendor->netid) { vendor->netid.next = state->tags; state->tags = &vendor->netid; @@ -418,7 +419,8 @@ static int dhcp6_no_relay(struct state *state, int msg_type, unsigned char *inbu for (enc_opt = opt6_user_vendor_first(opt6_ptr(opt, offset), enc_end); enc_opt; enc_opt = opt6_user_vendor_next(enc_opt, enc_end)) for (i = 0; i <= (opt6_user_vendor_len(enc_opt) - vendor->len); i++) - if (memcmp(vendor->data, opt6_user_vendor_ptr(enc_opt, i), vendor->len) == 0) + if (memcmp(vendor->data, opt6_user_vendor_ptr(enc_opt, i), vendor->len) == 0 && + vendor->netid.next == &vendor->netid) { vendor->netid.next = state->tags; state->tags = &vendor->netid;