From: Patrick Cheng Date: Sun, 24 Feb 2019 19:32:06 +0000 (-0800) Subject: fix dereferencing null pointer in file_new() X-Git-Tag: v3.4.0~120 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57742aa0df9b4dbef6532a1b8393056ae4d798bc;p=thirdparty%2Flibarchive.git fix dereferencing null pointer in file_new() 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 --- diff --git a/libarchive/archive_write_set_format_7zip.c b/libarchive/archive_write_set_format_7zip.c index f63a2266a..92a87f74e 100644 --- a/libarchive/archive_write_set_format_7zip.c +++ b/libarchive/archive_write_set_format_7zip.c @@ -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) {