[Dnsmasq-discuss] [PATCH] Check the remaining length before reading the next DHCPv6 FQDN label.
Dominik Derigs
git at dl6er.de
Fri Oct 30 06:19:45 UTC 2026
From: DL6ER <dl6er at dl6er.de>
The loop in dhcp6_no_relay() checks that a label fits into the option
only after reading its length byte. When the last label ends exactly at
the end of the option, e.g., flags followed by "01 61", op is advanced to
one past the option and the next iteration reads that byte. It cannot
start another label, as any length moves beyond the option, so this is a
one-byte over-read and the loop stops. a627a78 changed "len != 0" to
"len >= 1", which opt6_find(..., 1) already guarantees, so it did not
change this.
Stop before reading past the option.
Signed-off-by: DL6ER <dl6er at dl6er.de>
---
Hi Simon,
a627a78 does not change which FQDN options get parsed, as opt6_find(..., 1) already keeps len at 0 or more. The loop still reads the byte after the option when the last label ends exactly at its end. That byte cannot start another label, so it is a one-byte over-read, but this closes it.
Best regards,
Dominik
src/rfc3315.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/rfc3315.c b/src/rfc3315.c
index 79d420f..d8e3b72 100644
--- a/src/rfc3315.c
+++ b/src/rfc3315.c
@@ -508,7 +508,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, unsigned char *inbu
char *pq = daemon->dhcp_buff;
pp = op;
- while (*op != 0 && ((op + (*op)) - pp) < len)
+ while ((op - pp) < len && *op != 0 && ((op + (*op)) - pp) < len)
{
memcpy(pq, op+1, *op);
pq += *op;
--
2.53.0
More information about the Dnsmasq-discuss
mailing list