]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
fix dereferencing null pointer in file_new()
authorPatrick Cheng <patcheng@users.noreply.github.com>
Sun, 24 Feb 2019 19:32:06 +0000 (11:32 -0800)
committerMartin Matuška <martin@matuska.org>
Sun, 24 Feb 2019 19:32:06 +0000 (20:32 +0100)
file_new() sets file to NULL first.
when file_new() fails, file is set to NULL if it doesn't need to be freed
so, only free when need to. otherwise would deference a null pointer.

Found this from clang's analyzer
Fixes #1140

libarchive/archive_write_set_format_7zip.c

index f63a2266a85ede17a747a7c7796992fcf431c937..92a87f74e62507c0d5604a9a2b9060a4d713a1d4 100644 (file)
@@ -439,7 +439,8 @@ _7z_write_header(struct archive_write *a, struct archive_entry *entry)
 
        r = file_new(a, entry, &file);
        if (r < ARCHIVE_WARN) {
-               file_free(file);
+               if (file != NULL)
+                       file_free(file);
                return (r);
        }
        if (file->size == 0 && file->dir) {