Blame SOURCES/0004-invalid-IPv4-address.patch

c62ce2
From 907070918d5e81a515315b395f334e52589fe0fb Mon Sep 17 00:00:00 2001
c62ce2
From: Guy Harris <guy@alum.mit.edu>
c62ce2
Date: Wed, 18 Dec 2019 15:06:53 -0800
c62ce2
Subject: [PATCH] Check for invalid IPv4 addresses.
c62ce2
c62ce2
This should fix GitHub issue #893.
c62ce2
---
c62ce2
 gencode.c    | 9 ++++++++-
c62ce2
 nametoaddr.c | 9 ++++++++-
c62ce2
 2 files changed, 16 insertions(+), 2 deletions(-)
c62ce2
c62ce2
diff --git a/gencode.c b/gencode.c
c62ce2
index bdc35e646..040a55315 100644
c62ce2
--- a/gencode.c
c62ce2
+++ b/gencode.c
c62ce2
@@ -6947,11 +6947,15 @@ gen_mcode(compiler_state_t *cstate, const char *s1, const char *s2,
c62ce2
 		return (NULL);
c62ce2
 
c62ce2
 	nlen = __pcap_atoin(s1, &n);
c62ce2
+	if (nlen < 0)
c62ce2
+		bpf_error(cstate, "invalid IPv4 address '%s'", s1);
c62ce2
 	/* Promote short ipaddr */
c62ce2
 	n <<= 32 - nlen;
c62ce2
 
c62ce2
 	if (s2 != NULL) {
c62ce2
 		mlen = __pcap_atoin(s2, &m);
c62ce2
+		if (mlen < 0)
c62ce2
+			bpf_error(cstate, "invalid IPv4 address '%s'", s2);
c62ce2
 		/* Promote short ipaddr */
c62ce2
 		m <<= 32 - mlen;
c62ce2
 		if ((n & ~m) != 0)
c62ce2
@@ -7009,8 +7013,11 @@ gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q)
c62ce2
 		vlen = __pcap_atodn(s, &v);
c62ce2
 		if (vlen == 0)
c62ce2
 			bpf_error(cstate, "malformed decnet address '%s'", s);
c62ce2
-	} else
c62ce2
+	} else {
c62ce2
 		vlen = __pcap_atoin(s, &v);
c62ce2
+		if (vlen < 0)
c62ce2
+			bpf_error(cstate, "invalid IPv4 address '%s'", s);
c62ce2
+	}
c62ce2
 
c62ce2
 	switch (q.addr) {
c62ce2
 
c62ce2
diff --git a/nametoaddr.c b/nametoaddr.c
c62ce2
index 53070a285..13bf4c683 100644
c62ce2
--- a/nametoaddr.c
c62ce2
+++ b/nametoaddr.c
c62ce2
@@ -674,8 +674,15 @@ __pcap_atoin(const char *s, bpf_u_int32 *addr)
c62ce2
 	len = 0;
c62ce2
 	for (;;) {
c62ce2
 		n = 0;
c62ce2
-		while (*s && *s != '.')
c62ce2
+		while (*s && *s != '.') {
c62ce2
+			if (n > 25) {
c62ce2
+				/* The result will be > 255 */
c62ce2
+				return -1;
c62ce2
+			}
c62ce2
 			n = n * 10 + *s++ - '0';
c62ce2
+		}
c62ce2
+		if (n > 255)
c62ce2
+			return -1;
c62ce2
 		*addr <<= 8;
c62ce2
 		*addr |= n & 0xff;
c62ce2
 		len += 8;
c62ce2