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

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