Blame SOURCES/dnsmasq-2.76-gita3303e196.patch

a03026
From 2c1aec1e979a209eb2f2b035314a8c973b4ac269 Mon Sep 17 00:00:00 2001
a03026
From: Simon Kelley <simon@thekelleys.org.uk>
a03026
Date: Thu, 7 Sep 2017 20:45:00 +0100
a03026
Subject: [PATCH 7/9]     Don't return arcount=1 if EDNS0 RR won't fit in the
a03026
 packet.
a03026
a03026
    Omitting the EDNS0 RR but setting arcount gives a malformed packet.
a03026
    Also, don't accept UDP packet size less than 512 in recieved EDNS0.
a03026
---
a03026
 src/edns0.c   | 5 ++++-
a03026
 src/forward.c | 2 ++
a03026
 2 files changed, 6 insertions(+), 1 deletion(-)
a03026
a03026
diff --git a/src/edns0.c b/src/edns0.c
a03026
index 5bdc133..a8d0167 100644
a03026
--- a/src/edns0.c
a03026
+++ b/src/edns0.c
a03026
@@ -221,7 +221,10 @@ size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *l
a03026
 	  free(buff);
a03026
 	  p += rdlen;
a03026
 	}
a03026
-      header->arcount = htons(ntohs(header->arcount) + 1);
a03026
+      
a03026
+      /* Only bump arcount if RR is going to fit */ 
a03026
+      if (((ssize_t)optlen) <= (limit - (p + 4)))
a03026
+	header->arcount = htons(ntohs(header->arcount) + 1);
a03026
     }
a03026
   
a03026
   if (((ssize_t)optlen) > (limit - (p + 4)))
a03026
diff --git a/src/forward.c b/src/forward.c
a03026
index 9b464d3..0f8f462 100644
a03026
--- a/src/forward.c
a03026
+++ b/src/forward.c
a03026
@@ -1408,6 +1408,8 @@ void receive_query(struct listener *listen, time_t now)
a03026
 	 defaults to 512 */
a03026
       if (udp_size > daemon->edns_pktsz)
a03026
 	udp_size = daemon->edns_pktsz;
a03026
+      else if (udp_size < PACKETSZ)
a03026
+	udp_size = PACKETSZ; /* Sanity check - can't reduce below default. RFC 6891 6.2.3 */
a03026
     }
a03026
 
a03026
 #ifdef HAVE_AUTH
a03026
-- 
a03026
2.9.5
a03026