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

995285
From bb9b157146a62e655fb369b32684398c949fa1b1 Mon Sep 17 00:00:00 2001
995285
From: Tim Kientzle <kientzle@acm.org>
995285
Date: Sat, 21 Feb 2015 09:36:23 -0800
995285
Subject: [PATCH] Issue 407: Tar reader tries to examine last character of an
995285
 empty filename
995285
995285
Of interest:  While working on this, I noted that we have
995285
an existing test for tar files with empty filenames.
995285
That test asserts that the correct behavior here is for the
995285
format handler to return the entry with the empty filename
995285
and a status of ARCHIVE_OK.  Clients need to be robust against
995285
empty filenames.
995285
---
995285
 libarchive/archive_read_support_format_tar.c | 20 ++++++++------------
995285
 1 file changed, 8 insertions(+), 12 deletions(-)
995285
995285
diff --git a/libarchive/archive_read_support_format_tar.c b/libarchive/archive_read_support_format_tar.c
995285
index 37399a0..1e78093 100644
995285
--- a/libarchive/archive_read_support_format_tar.c
995285
+++ b/libarchive/archive_read_support_format_tar.c
995285
@@ -456,6 +456,7 @@ archive_read_format_tar_read_header(struct archive_read *a,
995285
 	static int default_dev;
995285
 	struct tar *tar;
995285
 	const char *p;
995285
+	const wchar_t *wp;
995285
 	int r;
995285
 	size_t l, unconsumed = 0;
995285
 
995285
@@ -506,27 +507,22 @@ archive_read_format_tar_read_header(struct archive_read *a,
995285
 		}
995285
 	}
995285
 
995285
-	if (r == ARCHIVE_OK) {
995285
+	if (r == ARCHIVE_OK && archive_entry_filetype(entry) == AE_IFREG) {
995285
 		/*
995285
 		 * "Regular" entry with trailing '/' is really
995285
 		 * directory: This is needed for certain old tar
995285
 		 * variants and even for some broken newer ones.
995285
 		 */
995285
-		const wchar_t *wp;
995285
-		wp = archive_entry_pathname_w(entry);
995285
-		if (wp != NULL) {
995285
+		if ((wp = archive_entry_pathname_w(entry)) != NULL) {
995285
 			l = wcslen(wp);
995285
-			if (archive_entry_filetype(entry) == AE_IFREG
995285
-			    && wp[l-1] == L'/')
995285
+			if (l > 0 && wp[l - 1] == L'/') {
995285
 				archive_entry_set_filetype(entry, AE_IFDIR);
995285
-		} else {
995285
-			p = archive_entry_pathname(entry);
995285
-			if (p == NULL)
995285
-				return (ARCHIVE_FAILED);
995285
+			}
995285
+		} else if ((p = archive_entry_pathname(entry)) != NULL) {
995285
 			l = strlen(p);
995285
-			if (archive_entry_filetype(entry) == AE_IFREG
995285
-			    && p[l-1] == '/')
995285
+			if (l > 0 && p[l - 1] == '/') {
995285
 				archive_entry_set_filetype(entry, AE_IFDIR);
995285
+			}
995285
 		}
995285
 	}
995285
 	return (r);
995285
-- 
995285
2.7.4
995285