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;