4506b2
From 6a0b00f0d66490e074323d04782e75c4ba8a3f8d Mon Sep 17 00:00:00 2001
4506b2
From: Simon Kelley <simon@thekelleys.org.uk>
4506b2
Date: Mon, 25 Sep 2017 20:19:55 +0100
4506b2
Subject: [PATCH 8/9] Misc code cleanups arising from Google analysis. No
4506b2
 security impleications or CVEs.
4506b2
4506b2
---
4506b2
 src/edns0.c   | 2 +-
4506b2
 src/rfc1035.c | 4 +++-
4506b2
 src/rfc2131.c | 2 +-
4506b2
 3 files changed, 5 insertions(+), 3 deletions(-)
4506b2
4506b2
diff --git a/src/edns0.c b/src/edns0.c
4506b2
index 89b2692..7ed5a47 100644
4506b2
--- a/src/edns0.c
4506b2
+++ b/src/edns0.c
4506b2
@@ -159,7 +159,7 @@ size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *l
4506b2
 	      /* delete option if we're to replace it. */
4506b2
 	      p -= 4;
4506b2
 	      rdlen -= len + 4;
4506b2
-	      memcpy(p, p+len+4, rdlen - i);
4506b2
+	      memmove(p, p+len+4, rdlen - i);
4506b2
 	      PUTSHORT(rdlen, lenp);
4506b2
 	      lenp -= 2;
4506b2
 	    }
4506b2
diff --git a/src/rfc1035.c b/src/rfc1035.c
4506b2
index 826f8a4..27af023 100644
4506b2
--- a/src/rfc1035.c
4506b2
+++ b/src/rfc1035.c
4506b2
@@ -37,7 +37,7 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
4506b2
 	/* end marker */
4506b2
 	{
4506b2
 	  /* check that there are the correct no of bytes after the name */
4506b2
-	  if (!CHECK_LEN(header, p, plen, extrabytes))
4506b2
+	  if (!CHECK_LEN(header, p1 ? p1 : p, plen, extrabytes))
4506b2
 	    return 0;
4506b2
 	  
4506b2
 	  if (isExtract)
4506b2
@@ -498,6 +498,8 @@ static unsigned char *do_doctor(unsigned char *p, int count, struct dns_header *
4506b2
 	    {
4506b2
 	      unsigned int i, len = *p1;
4506b2
 	      unsigned char *p2 = p1;
4506b2
+	      if ((p1 + len - p) >= rdlen)
4506b2
+	        return 0; /* bad packet */
4506b2
 	      /* make counted string zero-term  and sanitise */
4506b2
 	      for (i = 0; i < len; i++)
4506b2
 		{
4506b2
diff --git a/src/rfc2131.c b/src/rfc2131.c
4506b2
index f7c1f80..f3a7e53 100644
4506b2
--- a/src/rfc2131.c
4506b2
+++ b/src/rfc2131.c
4506b2
@@ -157,7 +157,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
4506b2
 	  for (offset = 0; offset < (len - 5); offset += elen + 5)
4506b2
 	    {
4506b2
 	      elen = option_uint(opt, offset + 4 , 1);
4506b2
-	      if (option_uint(opt, offset, 4) == BRDBAND_FORUM_IANA)
4506b2
+	      if (option_uint(opt, offset, 4) == BRDBAND_FORUM_IANA && offset + elen + 5 <= len)
4506b2
 		{
4506b2
 		  unsigned char *x = option_ptr(opt, offset + 5);
4506b2
 		  unsigned char *y = option_ptr(opt, offset + elen + 5);
4506b2
-- 
4506b2
2.9.5
4506b2