Blame SOURCES/freeradius-FR-GV-302-do-checks-based-on-pointers-not-on-decoded.patch

5fa452
From 019e35431db17661aa1d74d995fd0315af9a8dbf Mon Sep 17 00:00:00 2001
5fa452
From: "Alan T. DeKok" <aland@freeradius.org>
5fa452
Date: Tue, 27 Jun 2017 21:54:10 -0400
5fa452
Subject: [PATCH] FR-GV-302 - do checks based on pointers, not on decoded data
5fa452
5fa452
because decoded data may be empty
5fa452
---
5fa452
 src/lib/radius.c       | 10 +++++++++-
5fa452
 src/tests/unit/rfc.txt | 12 ++++++++++++
5fa452
 2 files changed, 21 insertions(+), 1 deletion(-)
5fa452
5fa452
diff --git a/src/lib/radius.c b/src/lib/radius.c
5fa452
index ad6b15b46..7114e1650 100644
5fa452
--- a/src/lib/radius.c
5fa452
+++ b/src/lib/radius.c
5fa452
@@ -2952,16 +2952,23 @@ static ssize_t data2vp_concat(TALLOC_CTX *ctx,
5fa452
 	 *	don't care about walking off of the end of it.
5fa452
 	 */
5fa452
 	while (ptr < end) {
5fa452
+		if (ptr[1] < 2) return -1;
5fa452
+		if ((ptr + ptr[1]) > end) return -1;
5fa452
+
5fa452
 		total += ptr[1] - 2;
5fa452
 
5fa452
 		ptr += ptr[1];
5fa452
 
5fa452
+		if (ptr == end) break;
5fa452
+
5fa452
 		/*
5fa452
 		 *	Attributes MUST be consecutive.
5fa452
 		 */
5fa452
 		if (ptr[0] != attr) break;
5fa452
 	}
5fa452
 
5fa452
+	end = ptr;
5fa452
+
5fa452
 	vp = fr_pair_afrom_da(ctx, da);
5fa452
 	if (!vp) return -1;
5fa452
 
5fa452
@@ -2974,7 +2981,7 @@ static ssize_t data2vp_concat(TALLOC_CTX *ctx,
5fa452
 
5fa452
 	total = 0;
5fa452
 	ptr = start;
5fa452
-	while (total < vp->vp_length) {
5fa452
+	while (ptr < end) {
5fa452
 		memcpy(p, ptr + 2, ptr[1] - 2);
5fa452
 		p += ptr[1] - 2;
5fa452
 		total += ptr[1] - 2;
5fa452
@@ -2982,6 +2989,7 @@ static ssize_t data2vp_concat(TALLOC_CTX *ctx,
5fa452
 	}
5fa452
 
5fa452
 	*pvp = vp;
5fa452
+
5fa452
 	return ptr - start;
5fa452
 }
5fa452
 
5fa452
diff --git a/src/tests/unit/rfc.txt b/src/tests/unit/rfc.txt
5fa452
index 00247940b..d870975e3 100644
5fa452
--- a/src/tests/unit/rfc.txt
5fa452
+++ b/src/tests/unit/rfc.txt
5fa452
@@ -178,6 +178,18 @@ data Failed to parse IPv4 address string "256/8"
5fa452
 attribute PMIP6-Home-IPv4-HoA = bob/8
5fa452
 data Failed to parse IPv4 address string "bob/8"
5fa452
 
5fa452
+#
5fa452
+#  A "concat" attribute, with no data
5fa452
+#
5fa452
+decode 89 02
5fa452
+data PKM-SS-Cert = 0x
5fa452
+
5fa452
+#
5fa452
+#  Or with weirdly formatted data
5fa452
+#
5fa452
+decode 89 03 ff 89 02 89 03 fe
5fa452
+data PKM-SS-Cert = 0xfffe
5fa452
+
5fa452
 $INCLUDE tunnel.txt
5fa452
 $INCLUDE errors.txt
5fa452
 $INCLUDE extended.txt
5fa452
-- 
5fa452
2.13.2
5fa452