e87dd3
From f2ad2cecb55825f7e4409222de1688b9ceebceda Mon Sep 17 00:00:00 2001
e87dd3
From: Simon Kelley <simon@thekelleys.org.uk>
e87dd3
Date: Mon, 25 Sep 2017 20:16:50 +0100
e87dd3
Subject: [PATCH 6/9]     Security fix, CVE-2017-14495, OOM in DNS response
e87dd3
 creation.
e87dd3
e87dd3
    Fix out-of-memory Dos vulnerability. An attacker which can
e87dd3
    send malicious DNS queries to dnsmasq can trigger memory
e87dd3
    allocations in the add_pseudoheader function
e87dd3
    The allocated memory is never freed which leads to a DoS
e87dd3
    through memory exhaustion. dnsmasq is vulnerable only
e87dd3
    if one of the following option is specified:
e87dd3
    --add-mac, --add-cpe-id or --add-subnet.
e87dd3
---
e87dd3
 src/edns0.c | 8 +++++++-
e87dd3
 1 file changed, 7 insertions(+), 1 deletion(-)
e87dd3
e87dd3
diff --git a/src/edns0.c b/src/edns0.c
e87dd3
index eed135e..5bdc133 100644
e87dd3
--- a/src/edns0.c
e87dd3
+++ b/src/edns0.c
e87dd3
@@ -192,9 +192,15 @@ size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *l
e87dd3
 	  !(p = skip_section(p, 
e87dd3
 			     ntohs(header->ancount) + ntohs(header->nscount) + ntohs(header->arcount), 
e87dd3
 			     header, plen)))
e87dd3
+      {
e87dd3
+	free(buff);
e87dd3
 	return plen;
e87dd3
+      }
e87dd3
       if (p + 11 > limit)
e87dd3
-       return plen; /* Too big */
e87dd3
+      {
e87dd3
+        free(buff);
e87dd3
+        return plen; /* Too big */
e87dd3
+      }
e87dd3
       *p++ = 0; /* empty name */
e87dd3
       PUTSHORT(T_OPT, p);
e87dd3
       PUTSHORT(udp_sz, p); /* max packet length, 512 if not given in EDNS0 header */
e87dd3
-- 
e87dd3
2.9.5
e87dd3