]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix a few obvious resource leaks and strcpy() misuses 1092/head
authorPavel Raiskup <praiskup@redhat.com>
Fri, 23 Nov 2018 12:48:34 +0000 (13:48 +0100)
committerPavel Raiskup <praiskup@redhat.com>
Fri, 23 Nov 2018 13:28:32 +0000 (14:28 +0100)
Per Coverity report.

cpio/cpio.c
libarchive/archive_acl.c
libarchive/archive_write_set_format_iso9660.c
libarchive/archive_write_set_format_mtree.c
libarchive/archive_write_set_format_pax.c
libarchive/archive_write_set_format_xar.c

index 9dddf417a5a5392fe01383a4abecefc8f45d2416..4fd394dea5f1659de49a46a543fc6ee020c5680e 100644 (file)
@@ -755,8 +755,10 @@ file_to_archive(struct cpio *cpio, const char *srcpath)
        }
        if (cpio->option_rename)
                destpath = cpio_rename(destpath);
-       if (destpath == NULL)
+       if (destpath == NULL) {
+               archive_entry_free(entry);
                return (0);
+       }
        archive_entry_copy_pathname(entry, destpath);
 
        /*
index 9941d2f6fdb2dc53c1ab47ecb085b16baae4c2be..6ce7ab66093a8dae33c9a04e2dc64f335d7a21a8 100644 (file)
@@ -753,8 +753,10 @@ archive_acl_to_text_w(struct archive_acl *acl, ssize_t *text_len, int flags,
                        append_entry_w(&wp, prefix, ap->type, ap->tag, flags,
                            wname, ap->permset, id);
                        count++;
-               } else if (r < 0 && errno == ENOMEM)
+               } else if (r < 0 && errno == ENOMEM) {
+                       free(ws);
                        return (NULL);
+               }
        }
 
        /* Add terminating character */
@@ -975,8 +977,10 @@ archive_acl_to_text_l(struct archive_acl *acl, ssize_t *text_len, int flags,
                        prefix = NULL;
                r = archive_mstring_get_mbs_l(
                    &ap->name, &name, &len, sc);
-               if (r != 0)
+               if (r != 0) {
+                       free(s);
                        return (NULL);
+               }
                if (count > 0)
                        *p++ = separator;
                if (name == NULL ||
index c0ca435d15c7421007f6b468d2f7180f66c6d527..badc88bad0c95071361f98eaaf6ea8eeea3e815a 100644 (file)
@@ -4899,10 +4899,10 @@ isofile_gen_utility_names(struct archive_write *a, struct isofile *file)
                if (p[0] == '/') {
                        if (p[1] == '/')
                                /* Convert '//' --> '/' */
-                               strcpy(p, p+1);
+                               memmove(p, p+1, strlen(p+1) + 1);
                        else if (p[1] == '.' && p[2] == '/')
                                /* Convert '/./' --> '/' */
-                               strcpy(p, p+2);
+                               memmove(p, p+2, strlen(p+2) + 1);
                        else if (p[1] == '.' && p[2] == '.' && p[3] == '/') {
                                /* Convert 'dir/dir1/../dir2/'
                                 *     --> 'dir/dir2/'
index 493d4735661f81408cc151ca8789be06c289fad5..0f2431e6abe0e69a58fd6cfc56fa1e0607376a46 100644 (file)
@@ -1810,10 +1810,10 @@ mtree_entry_setup_filenames(struct archive_write *a, struct mtree_entry *file,
                if (p[0] == '/') {
                        if (p[1] == '/')
                                /* Convert '//' --> '/' */
-                               strcpy(p, p+1);
+                               memmove(p, p+1, strlen(p+1) + 1);
                        else if (p[1] == '.' && p[2] == '/')
                                /* Convert '/./' --> '/' */
-                               strcpy(p, p+2);
+                               memmove(p, p+2, strlen(p+2) + 1);
                        else if (p[1] == '.' && p[2] == '.' && p[3] == '/') {
                                /* Convert 'dir/dir1/../dir2/'
                                 *     --> 'dir/dir2/'
index 6f78c48bd6518f0e2ed577014fc1ae5987e303a1..5a4c45a11e022690e02dfeb15f4b2db6e0cf0b1f 100644 (file)
@@ -522,11 +522,13 @@ add_pax_acl(struct archive_write *a,
                    ARCHIVE_ERRNO_FILE_FORMAT, "%s %s %s",
                    "Can't translate ", attr, " to UTF-8");
                return(ARCHIVE_WARN);
-       } else if (*p != '\0') {
+       }
+
+       if (*p != '\0') {
                add_pax_attr(&(pax->pax_header),
                    attr, p);
-               free(p);
        }
+       free(p);
        return(ARCHIVE_OK);
 }
 
index 495f0d441e5c1c3bd9462544943ae6d66a068c70..36d4a615e2aeda8a8c87705d4665c3c4ea4e69cc 100644 (file)
@@ -2120,10 +2120,10 @@ file_gen_utility_names(struct archive_write *a, struct file *file)
                if (p[0] == '/') {
                        if (p[1] == '/')
                                /* Convert '//' --> '/' */
-                               strcpy(p, p+1);
+                               memmove(p, p+1, strlen(p+1) + 1);
                        else if (p[1] == '.' && p[2] == '/')
                                /* Convert '/./' --> '/' */
-                               strcpy(p, p+2);
+                               memmove(p, p+2, strlen(p+2) + 1);
                        else if (p[1] == '.' && p[2] == '.' && p[3] == '/') {
                                /* Convert 'dir/dir1/../dir2/'
                                 *     --> 'dir/dir2/'
@@ -3169,8 +3169,10 @@ save_xattrs(struct archive_write *a, struct file *file)
                        checksum_update(&(xar->a_sumwrk),
                            xar->wbuff, size);
                        if (write_to_temp(a, xar->wbuff, size)
-                           != ARCHIVE_OK)
+                           != ARCHIVE_OK) {
+                               free(heap);
                                return (ARCHIVE_FATAL);
+                       }
                        if (r == ARCHIVE_OK) {
                                xar->stream.next_out = xar->wbuff;
                                xar->stream.avail_out = sizeof(xar->wbuff);