Blame SOURCES/fix-few-obvious-resource-leaks-covscan.patch

006282
From 9d178fe573818764a2d15e0a39691f5eb4e300f6 Mon Sep 17 00:00:00 2001
006282
From: Ondrej Dubaj <odubaj@redhat.com>
006282
Date: Mon, 27 May 2019 10:52:51 +0200
006282
Subject: [PATCH] Fix a few obvious resource leaks and strcpy() misuses
006282
006282
Per Coverity report.
006282
---
006282
 cpio/cpio.c                                      |  4 +++-
006282
 libarchive/archive_acl.c                         |  8 ++++++--
006282
 libarchive/archive_write_set_format_iso9660.c    |  4 ++--
006282
 libarchive/archive_write_set_format_mtree.c      |  4 ++--
006282
 libarchive/archive_write_set_format_pax.c        |  6 ++++--
006282
 libarchive/archive_write_set_format_xar.c        | 10 ++++++----
006282
 6 files changed, 23 insertions(+), 13 deletions(-)
006282
006282
diff --git a/cpio/cpio.c b/cpio/cpio.c
006282
index 5beedd0..6696bb5 100644
006282
--- a/cpio/cpio.c
006282
+++ b/cpio/cpio.c
006282
@@ -744,8 +744,10 @@ file_to_archive(struct cpio *cpio, const char *srcpath)
006282
 	}
006282
 	if (cpio->option_rename)
006282
 		destpath = cpio_rename(destpath);
006282
-	if (destpath == NULL)
006282
+	if (destpath == NULL) {
006282
+		archive_entry_free(entry);
006282
 		return (0);
006282
+	}
006282
 	archive_entry_copy_pathname(entry, destpath);
006282
 
006282
 	/*
006282
diff --git a/libarchive/archive_acl.c b/libarchive/archive_acl.c
006282
index b8b6b63..503f379 100644
006282
--- a/libarchive/archive_acl.c
006282
+++ b/libarchive/archive_acl.c
006282
@@ -753,8 +753,10 @@ archive_acl_to_text_w(struct archive_acl *acl, ssize_t *text_len, int flags,
006282
 			append_entry_w(&wp, prefix, ap->type, ap->tag, flags,
006282
 			    wname, ap->permset, id);
006282
 			count++;
006282
-		} else if (r < 0 && errno == ENOMEM)
006282
+		} else if (r < 0 && errno == ENOMEM) {
006282
+			free(ws);
006282
 			return (NULL);
006282
+		}
006282
 	}
006282
 
006282
 	/* Add terminating character */
006282
@@ -975,8 +977,10 @@ archive_acl_to_text_l(struct archive_acl *acl, ssize_t *text_len, int flags,
006282
 			prefix = NULL;
006282
 		r = archive_mstring_get_mbs_l(
006282
 		    &ap->name, &name, &len, sc);
006282
-		if (r != 0)
006282
+		if (r != 0) {
006282
+			free(s);
006282
 			return (NULL);
006282
+		}
006282
 		if (count > 0)
006282
 			*p++ = separator;
006282
 		if (name == NULL ||
006282
diff --git a/libarchive/archive_write_set_format_iso9660.c b/libarchive/archive_write_set_format_iso9660.c
006282
index c0ca435..badc88b 100644
006282
--- a/libarchive/archive_write_set_format_iso9660.c
006282
+++ b/libarchive/archive_write_set_format_iso9660.c
006282
@@ -4899,10 +4899,10 @@ isofile_gen_utility_names(struct archive_write *a, struct isofile *file)
006282
 		if (p[0] == '/') {
006282
 			if (p[1] == '/')
006282
 				/* Convert '//' --> '/' */
006282
-				strcpy(p, p+1);
006282
+				memmove(p, p+1, strlen(p+1) + 1);
006282
 			else if (p[1] == '.' && p[2] == '/')
006282
 				/* Convert '/./' --> '/' */
006282
-				strcpy(p, p+2);
006282
+				memmove(p, p+2, strlen(p+2) + 1);
006282
 			else if (p[1] == '.' && p[2] == '.' && p[3] == '/') {
006282
 				/* Convert 'dir/dir1/../dir2/'
006282
 				 *     --> 'dir/dir2/'
006282
diff --git a/libarchive/archive_write_set_format_mtree.c b/libarchive/archive_write_set_format_mtree.c
006282
index 493d473..0f2431e 100644
006282
--- a/libarchive/archive_write_set_format_mtree.c
006282
+++ b/libarchive/archive_write_set_format_mtree.c
006282
@@ -1810,10 +1810,10 @@ mtree_entry_setup_filenames(struct archive_write *a, struct mtree_entry *file,
006282
 		if (p[0] == '/') {
006282
 			if (p[1] == '/')
006282
 				/* Convert '//' --> '/' */
006282
-				strcpy(p, p+1);
006282
+				memmove(p, p+1, strlen(p+1) + 1);
006282
 			else if (p[1] == '.' && p[2] == '/')
006282
 				/* Convert '/./' --> '/' */
006282
-				strcpy(p, p+2);
006282
+				memmove(p, p+2, strlen(p+2) + 1);
006282
 			else if (p[1] == '.' && p[2] == '.' && p[3] == '/') {
006282
 				/* Convert 'dir/dir1/../dir2/'
006282
 				 *     --> 'dir/dir2/'
006282
diff --git a/libarchive/archive_write_set_format_pax.c b/libarchive/archive_write_set_format_pax.c
006282
index 0eaf733..4863e46 100644
006282
--- a/libarchive/archive_write_set_format_pax.c
006282
+++ b/libarchive/archive_write_set_format_pax.c
006282
@@ -522,11 +522,13 @@ add_pax_acl(struct archive_write *a,
006282
 		    ARCHIVE_ERRNO_FILE_FORMAT, "%s %s %s",
006282
 		    "Can't translate ", attr, " to UTF-8");
006282
 		return(ARCHIVE_WARN);
006282
-	} else if (*p != '\0') {
006282
+	}
006282
+
006282
+	if (*p != '\0') {
006282
 		add_pax_attr(&(pax->pax_header),
006282
 		    attr, p);
006282
-		free(p);
006282
 	}
006282
+	free(p);
006282
 	return(ARCHIVE_OK);
006282
 }
006282
 
006282
diff --git a/libarchive/archive_write_set_format_xar.c b/libarchive/archive_write_set_format_xar.c
006282
index 495f0d4..56cd33c 100644
006282
--- a/libarchive/archive_write_set_format_xar.c
006282
+++ b/libarchive/archive_write_set_format_xar.c
006282
@@ -2120,10 +2120,10 @@ file_gen_utility_names(struct archive_write *a, struct file *file)
006282
 		if (p[0] == '/') {
006282
 			if (p[1] == '/')
006282
 				/* Convert '//' --> '/' */
006282
-				strcpy(p, p+1);
006282
+				memmove(p, p+1, strlen(p+1) + 1);
006282
 			else if (p[1] == '.' && p[2] == '/')
006282
 				/* Convert '/./' --> '/' */
006282
-				strcpy(p, p+2);
006282
+				memmove(p, p+2, strlen(p+2) + 1);
006282
 			else if (p[1] == '.' && p[2] == '.' && p[3] == '/') {
006282
 				/* Convert 'dir/dir1/../dir2/'
006282
 				 *     --> 'dir/dir2/'
006282
@@ -3169,8 +3169,10 @@ save_xattrs(struct archive_write *a, struct file *file)
006282
 			checksum_update(&(xar->a_sumwrk),
006282
 			    xar->wbuff, size);
006282
 			if (write_to_temp(a, xar->wbuff, size)
006282
-			    != ARCHIVE_OK)
006282
-				return (ARCHIVE_FATAL);
006282
+			    != ARCHIVE_OK) {
006282
+					free(heap);
006282
+					return (ARCHIVE_FATAL);
006282
+			}
006282
 			if (r == ARCHIVE_OK) {
006282
 				xar->stream.next_out = xar->wbuff;
006282
 				xar->stream.avail_out = sizeof(xar->wbuff);
006282
-- 
006282
2.17.1
006282