Blame SOURCES/dnsmasq-2.77-underflow.patch

85f98a
From c82a594d95431e8615126621397ea595eb037a6b Mon Sep 17 00:00:00 2001
85f98a
From: Doran Moppert <dmoppert@redhat.com>
85f98a
Date: Tue, 26 Sep 2017 14:48:20 +0930
85f98a
Subject: [PATCH] google patch hand-applied
85f98a
85f98a
---
85f98a
 src/edns0.c   | 10 +++++-----
85f98a
 src/forward.c |  4 ++++
85f98a
 src/rfc1035.c |  2 ++
85f98a
 3 files changed, 11 insertions(+), 5 deletions(-)
85f98a
85f98a
diff --git a/src/edns0.c b/src/edns0.c
85f98a
index af33877..ba6ff0c 100644
85f98a
--- a/src/edns0.c
85f98a
+++ b/src/edns0.c
85f98a
@@ -212,11 +212,11 @@ size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *l
85f98a
       /* Copy back any options */
85f98a
       if (buff)
85f98a
 	{
85f98a
-          if (p + rdlen > limit)
85f98a
-          {
85f98a
-            free(buff);
85f98a
-            return plen; /* Too big */
85f98a
-          }
85f98a
+	  if (p + rdlen > limit)
85f98a
+	  {
85f98a
+	    free(buff);
85f98a
+	    return plen; /* Too big */
85f98a
+	  }
85f98a
 	  memcpy(p, buff, rdlen);
85f98a
 	  free(buff);
85f98a
 	  p += rdlen;
85f98a
diff --git a/src/forward.c b/src/forward.c
85f98a
index cdd11d3..3078f64 100644
85f98a
--- a/src/forward.c
85f98a
+++ b/src/forward.c
85f98a
@@ -1438,6 +1438,10 @@ void receive_query(struct listener *listen, time_t now)
85f98a
 	udp_size = PACKETSZ; /* Sanity check - can't reduce below default. RFC 6891 6.2.3 */
85f98a
     }
85f98a
 
85f98a
+  // Make sure the udp size is not smaller than the incoming message so that we
85f98a
+  // do not underflow
85f98a
+  if (udp_size < n) udp_size = n;
85f98a
+
85f98a
 #ifdef HAVE_AUTH
85f98a
   if (auth_dns)
85f98a
     {
85f98a
diff --git a/src/rfc1035.c b/src/rfc1035.c
85f98a
index b078b59..777911b 100644
85f98a
--- a/src/rfc1035.c
85f98a
+++ b/src/rfc1035.c
85f98a
@@ -1281,6 +1281,8 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
85f98a
   int nxdomain = 0, auth = 1, trunc = 0, sec_data = 1;
85f98a
   struct mx_srv_record *rec;
85f98a
   size_t len;
85f98a
+  // Make sure we do not underflow here too.
85f98a
+  if (qlen > (limit - ((char *)header))) return 0;
85f98a
 
85f98a
   if (ntohs(header->ancount) != 0 ||
85f98a
       ntohs(header->nscount) != 0 ||
85f98a
-- 
85f98a
2.14.3
85f98a