Blame SOURCES/0015-CVE-2020-8037.patch

3dbeb8
From 32027e199368dad9508965aae8cd8de5b6ab5231 Mon Sep 17 00:00:00 2001
3dbeb8
From: Guy Harris <guy@alum.mit.edu>
3dbeb8
Date: Sat, 18 Apr 2020 14:04:59 -0700
3dbeb8
Subject: [PATCH] PPP: When un-escaping, don't allocate a too-large buffer.
3dbeb8
3dbeb8
The buffer should be big enough to hold the captured data, but it
3dbeb8
doesn't need to be big enough to hold the entire on-the-network packet,
3dbeb8
if we haven't captured all of it.
3dbeb8
3dbeb8
(backported from commit e4add0b010ed6f2180dcb05a13026242ed935334)
3dbeb8
---
3dbeb8
 print-ppp.c | 18 ++++++++++++++----
3dbeb8
 1 file changed, 14 insertions(+), 4 deletions(-)
3dbeb8
3dbeb8
diff --git a/print-ppp.c b/print-ppp.c
3dbeb8
index 891761728..33fb03412 100644
3dbeb8
--- a/print-ppp.c
3dbeb8
+++ b/print-ppp.c
3dbeb8
@@ -1367,19 +1367,29 @@ print_bacp_config_options(netdissect_options *ndo,
3dbeb8
 	return 0;
3dbeb8
 }
3dbeb8
 
3dbeb8
+/*
3dbeb8
+ * Un-escape RFC 1662 PPP in HDLC-like framing, with octet escapes.
3dbeb8
+ * The length argument is the on-the-wire length, not the captured
3dbeb8
+ * length; we can only un-escape the captured part.
3dbeb8
+ */
3dbeb8
 static void
3dbeb8
 ppp_hdlc(netdissect_options *ndo,
3dbeb8
          const u_char *p, int length)
3dbeb8
 {
3dbeb8
+	u_int caplen = ndo->ndo_snapend - p;
3dbeb8
 	u_char *b, *t, c;
3dbeb8
 	const u_char *s;
3dbeb8
-	int i, proto;
3dbeb8
+	u_int i;
3dbeb8
+	int proto;
3dbeb8
 	const void *se;
3dbeb8
 
3dbeb8
+	if (caplen == 0)
3dbeb8
+		return;
3dbeb8
+
3dbeb8
         if (length <= 0)
3dbeb8
                 return;
3dbeb8
 
3dbeb8
-	b = (u_char *)malloc(length);
3dbeb8
+	b = (u_char *)malloc(caplen);
3dbeb8
 	if (b == NULL)
3dbeb8
 		return;
3dbeb8
 
3dbeb8
@@ -1388,10 +1398,10 @@ ppp_hdlc(netdissect_options *ndo,
3dbeb8
 	 * Do this so that we dont overwrite the original packet
3dbeb8
 	 * contents.
3dbeb8
 	 */
3dbeb8
-	for (s = p, t = b, i = length; i > 0 && ND_TTEST(*s); i--) {
3dbeb8
+	for (s = p, t = b, i = caplen; i != 0; i--) {
3dbeb8
 		c = *s++;
3dbeb8
 		if (c == 0x7d) {
3dbeb8
-			if (i <= 1 || !ND_TTEST(*s))
3dbeb8
+			if (i <= 1)
3dbeb8
 				break;
3dbeb8
 			i--;
3dbeb8
 			c = *s++ ^ 0x20;