]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix a potential NULL pointer dereference of `tar` in archive_read_support_format_tar...
authorngie <yaneurabeya@users.noreply.github.com>
Sun, 15 Oct 2017 17:59:07 +0000 (10:59 -0700)
committerJoerg Sonnenberger <joerg@bec.de>
Sun, 15 Oct 2017 17:59:07 +0000 (19:59 +0200)
If HAVE_COPYFILE_H is defined and allocating tar via calloc fails, tar
would be dereferenced before the tar == NULL check is done, causing a
NULL pointer dereference. Move the HAVE_COPYFILE_H block after the NULL
dereference check.

libarchive/archive_read_support_format_tar.c

index c3b1ecb66052188749fa54377977bab3471461f7..60800bb812e55da56d55452a8f3a49ad867a213e 100644 (file)
@@ -251,15 +251,15 @@ archive_read_support_format_tar(struct archive *_a)
            ARCHIVE_STATE_NEW, "archive_read_support_format_tar");
 
        tar = (struct tar *)calloc(1, sizeof(*tar));
-#ifdef HAVE_COPYFILE_H
-       /* Set this by default on Mac OS. */
-       tar->process_mac_extensions = 1;
-#endif
        if (tar == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate tar data");
                return (ARCHIVE_FATAL);
        }
+#ifdef HAVE_COPYFILE_H
+       /* Set this by default on Mac OS. */
+       tar->process_mac_extensions = 1;
+#endif
 
        r = __archive_read_register_format(a, tar, "tar",
            archive_read_format_tar_bid,