]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix use-after-free that Clang Static Analyzer pointed out.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 11 Sep 2012 11:11:09 +0000 (20:11 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 11 Sep 2012 11:11:09 +0000 (20:11 +0900)
libarchive/archive_write_set_format_7zip.c

index 39da009674d57e8827bdd317f102697c676a8402..e24f71ebeab3052b4a388ff07911f5ee989e06d1 100644 (file)
@@ -442,6 +442,14 @@ _7z_write_header(struct archive_write *a, struct archive_entry *entry)
                file_free(file);
                return (r);
        }
+       if (file->size == 0 && file->dir) {
+               if (!__archive_rb_tree_insert_node(&(zip->rbtree),
+                   (struct archive_rb_node *)file)) {
+                       /* We have already had the same file. */
+                       file_free(file);
+                       return (ARCHIVE_OK);
+               }
+       }
 
        if (file->flg & MTIME_IS_SET)
                zip->total_number_time_defined[MTIME]++;
@@ -450,11 +458,6 @@ _7z_write_header(struct archive_write *a, struct archive_entry *entry)
        if (file->flg & ATIME_IS_SET)
                zip->total_number_time_defined[ATIME]++;
 
-       if (file->size == 0 && file->dir) {
-               if (!__archive_rb_tree_insert_node(&(zip->rbtree),
-                   (struct archive_rb_node *)file))
-                       file_free(file);
-       }
        zip->total_number_entry++;
        zip->total_bytes_entry_name += file->name_len + 2;
        if (file->size == 0) {