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 <dickson.wu@certik.com> for spotting this.
This commit is contained in:
Simon Kelley committed 2026-12-04 20:51:21 +00:00
1 parent 035eaa22ad
commit 7d58e5dee5
1 file changed
+6 -4
+6 -4
View File
@@ -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;