Blame SOURCES/libarchive-3.1.2-CVE-2015-8931.patch

58251f
From 11f6da24b13840397fee87445859d7f2a2ac02f8 Mon Sep 17 00:00:00 2001
58251f
From: Tim Kientzle <kientzle@acm.org>
58251f
Date: Sat, 16 May 2015 12:16:28 -0700
58251f
Subject: [PATCH] This is a combination of 2 commits. == The first commit's
58251f
 message is: ==
58251f
58251f
Issue #539:  Try a different way to compute max/min time_t values.
58251f
58251f
== This is the 2nd commit message: ==
58251f
58251f
Don't try to be smart about probing the min/max tim_t values.
58251f
Just assume that a signed time_t is really a 64-bit or 32-bit integer.
58251f
---
58251f
 libarchive/archive_read_support_format_mtree.c | 47 ++++++++++++++------------
58251f
 1 file changed, 25 insertions(+), 22 deletions(-)
58251f
58251f
diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c
58251f
index 64d5e67..3abe198 100644
58251f
--- a/libarchive/archive_read_support_format_mtree.c
58251f
+++ b/libarchive/archive_read_support_format_mtree.c
58251f
@@ -139,16 +139,22 @@ get_time_t_max(void)
58251f
 #if defined(TIME_T_MAX)
58251f
 	return TIME_T_MAX;
58251f
 #else
58251f
-	static time_t t;
58251f
-	time_t a;
58251f
-	if (t == 0) {
58251f
-		a = 1;
58251f
-		while (a > t) {
58251f
-			t = a;
58251f
-			a = a * 2 + 1;
58251f
+	/* ISO C allows time_t to be a floating-point type,
58251f
+	   but POSIX requires an integer type.  The following
58251f
+	   should work on any system that follows the POSIX
58251f
+	   conventions. */
58251f
+	if (((time_t)0) < ((time_t)-1)) {
58251f
+		/* Time_t is unsigned */
58251f
+		return (~(time_t)0);
58251f
+	} else {
58251f
+		/* Time_t is signed. */
58251f
+		/* Assume it's the same as int64_t or int32_t */
58251f
+		if (sizeof(time_t) == sizeof(int64_t)) {
58251f
+			return (time_t)INT64_MAX;
58251f
+		} else {
58251f
+			return (time_t)INT32_MAX;
58251f
 		}
58251f
 	}
58251f
-	return t;
58251f
 #endif
58251f
 }
58251f
 
58251f
@@ -158,20 +164,17 @@ get_time_t_min(void)
58251f
 #if defined(TIME_T_MIN)
58251f
 	return TIME_T_MIN;
58251f
 #else
58251f
-	/* 't' will hold the minimum value, which will be zero (if
58251f
-	 * time_t is unsigned) or -2^n (if time_t is signed). */
58251f
-	static int computed;
58251f
-	static time_t t;
58251f
-	time_t a;
58251f
-	if (computed == 0) {
58251f
-		a = (time_t)-1;
58251f
-		while (a < t) {
58251f
-			t = a;
58251f
-			a = a * 2;
58251f
-		}			
58251f
-		computed = 1;
58251f
+	if (((time_t)0) < ((time_t)-1)) {
58251f
+		/* Time_t is unsigned */
58251f
+		return (time_t)0;
58251f
+	} else {
58251f
+		/* Time_t is signed. */
58251f
+		if (sizeof(time_t) == sizeof(int64_t)) {
58251f
+			return (time_t)INT64_MIN;
58251f
+		} else {
58251f
+			return (time_t)INT32_MIN;
58251f
+		}
58251f
 	}
58251f
-	return t;
58251f
 #endif
58251f
 }
58251f
 
58251f
@@ -1562,7 +1565,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
58251f
 			int64_t m;
58251f
 			int64_t my_time_t_max = get_time_t_max();
58251f
 			int64_t my_time_t_min = get_time_t_min();
58251f
-			long ns;
58251f
+			long ns = 0;
58251f
 
58251f
 			*parsed_kws |= MTREE_HAS_MTIME;
58251f
 			m = mtree_atol10(&val;;
58251f
-- 
58251f
2.7.4
58251f