|
|
e20e41 |
From d4f2e0b8d8f0b5daa0d468f62a0d5f1df58ac325 Mon Sep 17 00:00:00 2001
|
|
|
e20e41 |
From: Doran Moppert <dmoppert@redhat.com>
|
|
|
e20e41 |
Date: Tue, 26 Sep 2017 14:48:20 +0930
|
|
|
e20e41 |
Subject: [PATCH 9/9] google patch hand-applied
|
|
|
e20e41 |
|
|
|
e20e41 |
---
|
|
|
e20e41 |
src/edns0.c | 10 +++++-----
|
|
|
e20e41 |
src/forward.c | 4 ++++
|
|
|
e20e41 |
src/rfc1035.c | 6 ++++--
|
|
|
e20e41 |
3 files changed, 13 insertions(+), 7 deletions(-)
|
|
|
e20e41 |
|
|
|
e20e41 |
diff --git a/src/edns0.c b/src/edns0.c
|
|
|
e20e41 |
index 0552d38..bec4a36 100644
|
|
|
e20e41 |
--- a/src/edns0.c
|
|
|
e20e41 |
+++ b/src/edns0.c
|
|
|
e20e41 |
@@ -212,11 +212,11 @@ size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *l
|
|
|
e20e41 |
/* Copy back any options */
|
|
|
e20e41 |
if (buff)
|
|
|
e20e41 |
{
|
|
|
e20e41 |
- if (p + rdlen > limit)
|
|
|
e20e41 |
- {
|
|
|
e20e41 |
- free(buff);
|
|
|
e20e41 |
- return plen; /* Too big */
|
|
|
e20e41 |
- }
|
|
|
e20e41 |
+ if (p + rdlen > limit)
|
|
|
e20e41 |
+ {
|
|
|
e20e41 |
+ free(buff);
|
|
|
e20e41 |
+ return plen; /* Too big */
|
|
|
e20e41 |
+ }
|
|
|
e20e41 |
memcpy(p, buff, rdlen);
|
|
|
e20e41 |
free(buff);
|
|
|
e20e41 |
p += rdlen;
|
|
|
e20e41 |
diff --git a/src/forward.c b/src/forward.c
|
|
|
e20e41 |
index 0f8f462..a729c06 100644
|
|
|
e20e41 |
--- a/src/forward.c
|
|
|
e20e41 |
+++ b/src/forward.c
|
|
|
e20e41 |
@@ -1412,6 +1412,10 @@ void receive_query(struct listener *listen, time_t now)
|
|
|
e20e41 |
udp_size = PACKETSZ; /* Sanity check - can't reduce below default. RFC 6891 6.2.3 */
|
|
|
e20e41 |
}
|
|
|
e20e41 |
|
|
|
e20e41 |
+ // Make sure the udp size is not smaller than the incoming message so that we
|
|
|
e20e41 |
+ // do not underflow
|
|
|
e20e41 |
+ if (udp_size < n) udp_size = n;
|
|
|
e20e41 |
+
|
|
|
e20e41 |
#ifdef HAVE_AUTH
|
|
|
e20e41 |
if (auth_dns)
|
|
|
e20e41 |
{
|
|
|
e20e41 |
diff --git a/src/rfc1035.c b/src/rfc1035.c
|
|
|
e20e41 |
index 917bac2..ae65702 100644
|
|
|
e20e41 |
--- a/src/rfc1035.c
|
|
|
e20e41 |
+++ b/src/rfc1035.c
|
|
|
e20e41 |
@@ -1182,8 +1182,8 @@ int add_resource_record(struct dns_header *header, char *limit, int *truncp, int
|
|
|
e20e41 |
va_end(ap); /* clean up variable argument pointer */
|
|
|
e20e41 |
|
|
|
e20e41 |
j = p - sav - 2;
|
|
|
e20e41 |
- /* this has already been checked against limit before */
|
|
|
e20e41 |
- PUTSHORT(j, sav); /* Now, store real RDLength */
|
|
|
e20e41 |
+ /* this has already been checked against limit before */
|
|
|
e20e41 |
+ PUTSHORT(j, sav); /* Now, store real RDLength */
|
|
|
e20e41 |
|
|
|
e20e41 |
/* check for overflow of buffer */
|
|
|
e20e41 |
if (limit && ((unsigned char *)limit - p) < 0)
|
|
|
e20e41 |
@@ -1243,6 +1243,8 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|
|
e20e41 |
int nxdomain = 0, auth = 1, trunc = 0, sec_data = 1;
|
|
|
e20e41 |
struct mx_srv_record *rec;
|
|
|
e20e41 |
size_t len;
|
|
|
e20e41 |
+ // Make sure we do not underflow here too.
|
|
|
e20e41 |
+ if (qlen > (limit - ((char *)header))) return 0;
|
|
|
e20e41 |
|
|
|
e20e41 |
if (ntohs(header->ancount) != 0 ||
|
|
|
e20e41 |
ntohs(header->nscount) != 0 ||
|
|
|
e20e41 |
--
|
|
|
e20e41 |
2.9.5
|
|
|
e20e41 |
|