midipix / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame patches/libarchive-3.1.2.local.patch

Lucio Andrés Illanes Albornoz (arab, vxp) 951620
--- libarchive-3.1.2/cpio/bsdcpio.1.orig
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+++ libarchive-3.1.2/cpio/bsdcpio.1
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
@@ -156,7 +156,8 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 .It Fl Fl insecure
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 (i and p mode only)
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 Disable security checks during extraction or copying.
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
-This allows extraction via symbolic links and path names containing
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+This allows extraction via symbolic links, absolute paths,
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+and path names containing
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 .Sq ..
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 in the name.
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 .It Fl J , Fl Fl xz
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
--- libarchive-3.1.2/cpio/cpio.c.orig
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+++ libarchive-3.1.2/cpio/cpio.c
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
@@ -179,6 +179,7 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	cpio->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_SYMLINKS;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NODOTDOT;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	cpio->extract_flags |= ARCHIVE_EXTRACT_PERM;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	cpio->extract_flags |= ARCHIVE_EXTRACT_FFLAGS;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	cpio->extract_flags |= ARCHIVE_EXTRACT_ACL;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
@@ -264,6 +265,7 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 		case OPTION_INSECURE:
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 			cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_SYMLINKS;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 			cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+			cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 			break;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 		case 'L': /* GNU cpio */
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 			cpio->option_follow_links = 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
@@ -300,6 +302,7 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 				    "Cannot use both -p and -%c", cpio->mode);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 			cpio->mode = opt;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 			cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+			cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 			break;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 		case OPTION_PRESERVE_OWNER:
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 			cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
--- libarchive-3.1.2/libarchive/archive.h.orig
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+++ libarchive-3.1.2/libarchive/archive.h
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
@@ -562,6 +562,8 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 /* Default: Do not use HFS+ compression if it was not compressed. */
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 /* This has no effect except on Mac OS v10.6 or later. */
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 #define	ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED	(0x8000)
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+/* Default: Do not reject entries with absolute paths */
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000)
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 __LA_DECL int archive_read_extract(struct archive *, struct archive_entry *,
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 		     int flags);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
--- libarchive-3.1.2/libarchive/archive_write_disk.3.orig
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+++ libarchive-3.1.2/libarchive/archive_write_disk.3
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
@@ -177,6 +177,9 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 Note that paths ending in
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 .Pa ..
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 always cause an error, regardless of this flag.
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+.It Cm ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+Refuse to extract an absolute path.
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+The default is to not refuse such paths.
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 .It Cm ARCHIVE_EXTRACT_SPARSE
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 Scan data for blocks of NUL bytes and try to recreate them with holes.
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 This results in sparse files, independent of whether the archive format
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
--- libarchive-3.1.2/libarchive/archive_write_disk_posix.c.orig
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+++ libarchive-3.1.2/libarchive/archive_write_disk_posix.c
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
@@ -2504,8 +2504,9 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 /*
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
  * Canonicalize the pathname.  In particular, this strips duplicate
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
  * '/' characters, '.' elements, and trailing '/'.  It also raises an
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
- * error for an empty path, a trailing '..' or (if _SECURE_NODOTDOT is
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
- * set) any '..' in the path.
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+ * error for an empty path, a trailing '..', (if _SECURE_NODOTDOT is
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+ * set) any '..' in the path or (if ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+ * is set) if the path is absolute.
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
  */
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 static int
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 cleanup_pathname(struct archive_write_disk *a)
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
@@ -2524,8 +2525,15 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	cleanup_pathname_win(a);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 #endif
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	/* Skip leading '/'. */
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
-	if (*src == '/')
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	if (*src == '/') {
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+		if (a->flags & ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS) {
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+			                  "Path is absolute");
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+			return (ARCHIVE_FAILED);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+		}
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 		separator = *src++;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	}
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	/* Scan the pathname one element at a time. */
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	for (;;) {
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
--- libarchive-3.1.2/libarchive/test/test_write_disk_secure.c.orig
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+++ libarchive-3.1.2/libarchive/test/test_write_disk_secure.c
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
@@ -178,6 +178,29 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	assert(S_ISDIR(st.st_mode));
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	archive_entry_free(ae);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	/*
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	 * Without security checks, we should be able to
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	 * extract an absolute path.
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	 */
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	assert((ae = archive_entry_new()) != NULL);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	archive_entry_copy_pathname(ae, "/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp");
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	archive_entry_set_mode(ae, S_IFREG | 0777);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	assert(0 == archive_write_header(a, ae));
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	assert(0 == archive_write_finish_entry(a));
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	assertFileExists("/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp");
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	assert(0 == unlink("/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp"));
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	/* But with security checks enabled, this should fail. */
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	assert(archive_entry_clear(ae) != NULL);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	archive_entry_copy_pathname(ae, "/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp");
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	archive_entry_set_mode(ae, S_IFREG | 0777);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	archive_write_disk_set_options(a, ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	failure("Extracting an absolute path should fail here.");
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	assertEqualInt(ARCHIVE_FAILED, archive_write_header(a, ae));
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	archive_entry_free(ae);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	assert(0 == archive_write_finish_entry(a));
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	assertFileNotExists("/tmp/libarchive_test-test_write_disk_secure-absolute_path.tmp");
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	assertEqualInt(ARCHIVE_OK, archive_write_free(a));
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	/* Test the entries on disk. */
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
--- libarchive-3.1.2/libarchive/archive_write.c.orig	2016-06-03 13:15:42.862830537 +0000
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+++ libarchive-3.1.2/libarchive/archive_write.c	2016-06-03 13:19:01.590826126 +0000
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
@@ -671,8 +671,12 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 _archive_write_data(struct archive *_a, const void *buff, size_t s)
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 {
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	struct archive_write *a = (struct archive_write *)_a;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	const size_t max_write = INT_MAX;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	    ARCHIVE_STATE_DATA, "archive_write_data");
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	/* In particular, this catches attempts to pass negative values. */
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+	if (s > max_write)
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
+		s = max_write;
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	archive_clear_error(&a->archive);
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 	return ((a->format_write_data)(a, buff, s));
Lucio Andrés Illanes Albornoz (arab, vxp) 951620
 }