From 8735c815843cc1d527266c33439f2495942320d2 Mon Sep 17 00:00:00 2001 From: Michihiro NAKAJIMA Date: Tue, 11 Sep 2012 20:11:09 +0900 Subject: [PATCH] Fix use-after-free that Clang Static Analyzer pointed out. --- libarchive/archive_write_set_format_7zip.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libarchive/archive_write_set_format_7zip.c b/libarchive/archive_write_set_format_7zip.c index 39da00967..e24f71ebe 100644 --- a/libarchive/archive_write_set_format_7zip.c +++ b/libarchive/archive_write_set_format_7zip.c @@ -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) { -- 2.47.3