Blame SOURCES/dnsmasq-2.77-underflow.patch

53807b
From 684bede049a006a0a47ce88f017ada9f73bf4430 Mon Sep 17 00:00:00 2001
53807b
From: Doran Moppert <dmoppert@redhat.com>
53807b
Date: Tue, 26 Sep 2017 14:48:20 +0930
53807b
Subject: [PATCH] google patch hand-applied
53807b
53807b
---
53807b
 src/edns0.c   | 10 +++++-----
53807b
 src/forward.c |  4 ++++
53807b
 src/rfc1035.c |  3 +++
53807b
 3 files changed, 12 insertions(+), 5 deletions(-)
53807b
53807b
diff --git a/src/edns0.c b/src/edns0.c
53807b
index d75d3cc..7d8cf7f 100644
53807b
--- a/src/edns0.c
53807b
+++ b/src/edns0.c
53807b
@@ -212,11 +212,11 @@ size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *l
53807b
       /* Copy back any options */
53807b
       if (buff)
53807b
 	{
53807b
-          if (p + rdlen > limit)
53807b
-          {
53807b
-            free(buff);
53807b
-            return plen; /* Too big */
53807b
-          }
53807b
+	  if (p + rdlen > limit)
53807b
+	  {
53807b
+	    free(buff);
53807b
+	    return plen; /* Too big */
53807b
+	  }
53807b
 	  memcpy(p, buff, rdlen);
53807b
 	  free(buff);
53807b
 	  p += rdlen;
53807b
diff --git a/src/forward.c b/src/forward.c
53807b
index ed9c8f6..77059ed 100644
53807b
--- a/src/forward.c
53807b
+++ b/src/forward.c
53807b
@@ -1542,6 +1542,10 @@ void receive_query(struct listener *listen, time_t now)
53807b
 	udp_size = PACKETSZ; /* Sanity check - can't reduce below default. RFC 6891 6.2.3 */
53807b
     }
53807b
 
53807b
+  // Make sure the udp size is not smaller than the incoming message so that we
53807b
+  // do not underflow
53807b
+  if (udp_size < n) udp_size = n;
53807b
+
53807b
 #ifdef HAVE_AUTH
53807b
   if (auth_dns)
53807b
     {
53807b
diff --git a/src/rfc1035.c b/src/rfc1035.c
53807b
index f1edc45..15041cc 100644
53807b
--- a/src/rfc1035.c
53807b
+++ b/src/rfc1035.c
53807b
@@ -1326,6 +1326,9 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
53807b
   size_t len;
53807b
   int rd_bit = (header->hb3 & HB3_RD);
53807b
 
53807b
+  // Make sure we do not underflow here too.
53807b
+  if (qlen > (limit - ((char *)header))) return 0;
53807b
+
53807b
   /* never answer queries with RD unset, to avoid cache snooping. */
53807b
   if (ntohs(header->ancount) != 0 ||
53807b
       ntohs(header->nscount) != 0 ||
53807b
-- 
53807b
2.21.1
53807b