Blame SOURCES/file-5.11-CVE-2014-9652.patch

0233e9
From 59e63838913eee47f5c120a6c53d4565af638158 Mon Sep 17 00:00:00 2001
0233e9
From: Christos Zoulas <christos@zoulas.com>
0233e9
Date: Tue, 11 Nov 2014 17:48:23 +0000
0233e9
Subject: [PATCH] PR/398: Correctly truncate pascal strings (fixes out of
0233e9
 bounds read of 1, 2, or 4 bytes).
0233e9
0233e9
---
0233e9
 src/softmagic.c | 9 ++++++---
0233e9
 1 file changed, 6 insertions(+), 3 deletions(-)
0233e9
0233e9
diff --git a/src/softmagic.c b/src/softmagic.c
0233e9
index dbb670a..2b15f2c 100644
0233e9
--- a/src/softmagic.c
0233e9
+++ b/src/softmagic.c
83d9a8
@@ -822,14 +822,17 @@ mconvert(struct magic_set *ms, struct magic *m)
0233e9
 		size_t sz = file_pstring_length_size(m);
0233e9
 		char *ptr1 = p->s, *ptr2 = ptr1 + sz;
0233e9
 		size_t len = file_pstring_get_length(m, ptr1);
0233e9
-		if (len >= sizeof(p->s)) {
0233e9
+		sz = sizeof(p->s) - sz; /* maximum length of string */
0233e9
+		if (len >= sz) {
0233e9
 			/*
0233e9
 			 * The size of the pascal string length (sz)
0233e9
 			 * is 1, 2, or 4. We need at least 1 byte for NUL
0233e9
 			 * termination, but we've already truncated the
0233e9
 			 * string by p->s, so we need to deduct sz.
0233e9
+			 * Because we can use one of the bytes of the length
0233e9
+			 * after we shifted as NUL termination.
0233e9
 			 */ 
0233e9
-			len = sizeof(p->s) - sz;
0233e9
+			len = sz;
0233e9
 		}
0233e9
 		while (len--)
0233e9
 			*ptr1++ = *ptr2++;