Fix 1-byte OOB read in edns0.c

In edns0.c:482, check_source reads one byte beyond the allocated
packet when a malformed upstream ECS reply reaches the
buffer end under --add-subnet.

Credit to Dickson Wu for the find and the patch.
This commit is contained in:
Dickson Wu authored and Simon Kelley committed 2026-12-04 21:04:42 +00:00
1 parent 7d58e5dee5
commit c936b17bc7
1 file changed
+6 -3
+6 -3
View File
@@ -478,12 +478,15 @@ int check_source(struct dns_header *header, size_t plen, unsigned char *pseudohe
{
if (peer)
{
/* make sure this doesn't mismatch. */
/* make sure this doesn't mismatch. Check the length first: an option
shorter than 4 bytes has no scope_netmask byte to read. */
if (len != calc_len)
return 0;
opt.scope_netmask = p[3];
if (len != calc_len || memcmp(p, &opt, len) != 0)
if (memcmp(p, &opt, len) != 0)
return 0;
}
else if (((struct subnet_opt *)p)->source_netmask != 0)
else if (len >= 3 && ((struct subnet_opt *)p)->source_netmask != 0)
return 0;
}
p += len;