653d32
From af6d64cfa4f8ff64da1b5cd6cacd06ae3c095c37 Mon Sep 17 00:00:00 2001
653d32
From: "Alan T. DeKok" <aland@freeradius.org>
653d32
Date: Mon, 3 Jul 2017 15:37:44 -0400
653d32
Subject: [PATCH] FR-GV-303 - do memchr() of end-p, not q-p
653d32
653d32
---
653d32
 src/modules/proto_dhcp/dhcp.c | 20 +++++++++-----------
653d32
 1 file changed, 9 insertions(+), 11 deletions(-)
653d32
653d32
diff --git a/src/modules/proto_dhcp/dhcp.c b/src/modules/proto_dhcp/dhcp.c
653d32
index a66a931cb..dbfe81747 100644
653d32
--- a/src/modules/proto_dhcp/dhcp.c
653d32
+++ b/src/modules/proto_dhcp/dhcp.c
653d32
@@ -774,25 +774,23 @@ static int fr_dhcp_attr2vp(TALLOC_CTX *ctx, VALUE_PAIR **vp_p, uint8_t const *da
653d32
 		 *	multiple additional VPs
653d32
 		 */
653d32
 		fr_cursor_init(&cursor, vp_p);
653d32
-		for (;;) {
653d32
-			q = memchr(p, '\0', q - p);
653d32
+		while (p < end) {
653d32
+			q = memchr(p, '\0', end - p);
653d32
 			/* Malformed but recoverable */
653d32
 			if (!q) q = end;
653d32
 
653d32
 			fr_pair_value_bstrncpy(vp, (char const *)p, q - p);
653d32
 			p = q + 1;
653d32
 
653d32
+			if (p >= end) break;
653d32
+
653d32
 			/* Need another VP for the next round */
653d32
-			if (p < end) {
653d32
-				vp = fr_pair_afrom_da(ctx, vp->da);
653d32
-				if (!vp) {
653d32
-					fr_pair_list_free(vp_p);
653d32
-					return -1;
653d32
-				}
653d32
-				fr_cursor_insert(&cursor, vp);
653d32
-				continue;
653d32
+			vp = fr_pair_afrom_da(ctx, vp->da);
653d32
+			if (!vp) {
653d32
+				fr_pair_list_free(vp_p);
653d32
+				return -1;
653d32
 			}
653d32
-			break;
653d32
+			fr_cursor_insert(&cursor, vp);
653d32
 		}
653d32
 	}
653d32
 		break;
653d32
-- 
653d32
2.13.2
653d32