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