From c936b17bc7517863160722dd87b6ea046c3575b2 Mon Sep 17 00:00:00 2001 From: Dickson Wu Date: Fri, 4 Dec 2026 21:04:42 +0000 Subject: [PATCH] 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. --- src/edns0.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/edns0.c b/src/edns0.c index 94881c2..2a57751 100644 --- a/src/edns0.c +++ b/src/edns0.c @@ -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;