From 8fbce6094dc3acad11c464723d97d3215951c5d4 Mon Sep 17 00:00:00 2001 From: liaichun Date: Mon, 20 Apr 2020 15:26:17 +0800 Subject: [PATCH] dnsmasq-2.77-underflow --- src/forward.c | 3 +++ src/rfc1035.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/forward.c b/src/forward.c index fde554d..47ccd91 100644 --- a/src/forward.c +++ b/src/forward.c @@ -1546,6 +1546,9 @@ void receive_query(struct listener *listen, time_t now) else if (udp_size < PACKETSZ) udp_size = PACKETSZ; /* Sanity check - can't reduce below default. RFC 6891 6.2.3 */ } + // Make sure the udp size is not smaller than the incoming message so that we + // do not underflow + if (udp_size < n) udp_size = n; #ifdef HAVE_AUTH if (auth_dns) diff --git a/src/rfc1035.c b/src/rfc1035.c index fefe63d..6253794 100644 --- a/src/rfc1035.c +++ b/src/rfc1035.c @@ -1340,6 +1340,9 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen, size_t len; int rd_bit = (header->hb3 & HB3_RD); + // Make sure we do not underflow here too. + if (qlen > (limit - ((char *)header))) return 0; + /* never answer queries with RD unset, to avoid cache snooping. */ if (ntohs(header->ancount) != 0 || ntohs(header->nscount) != 0 || -- 2.23.0