]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Checks for null references (#2251)
authorFatima Qarni <fatima.q832@gmail.com>
Sat, 22 Jun 2024 22:49:53 +0000 (17:49 -0500)
committerGitHub <noreply@github.com>
Sat, 22 Jun 2024 22:49:53 +0000 (15:49 -0700)
Microsoft's static analysis tool found some vulnerabilities from
unguarded null references that I changed in
[microsoft/cmake](https://github.com/microsoft/cmake). Pushing these
changes upstream so they can be added to
[kitware/cmake](https://github.com/Kitware/CMake).

libarchive/archive_read_support_format_7zip.c
libarchive/archive_write_set_format_cpio_binary.c
libarchive/archive_write_set_format_cpio_odc.c

index e322808e7320f87ae6f0428b60e10e4a5de82577..b1e0c91ad1a9fff56a2c220bf77e8d6d5818dd97 100644 (file)
@@ -1063,7 +1063,7 @@ ppmd_read(void *p)
                ssize_t bytes_avail = 0;
                const uint8_t* data = __archive_read_ahead(a,
                    (size_t)zip->ppstream.stream_in+1, &bytes_avail);
-               if(bytes_avail < zip->ppstream.stream_in+1) {
+               if(data == NULL || bytes_avail < zip->ppstream.stream_in+1) {
                        archive_set_error(&a->archive,
                            ARCHIVE_ERRNO_FILE_FORMAT,
                            "Truncated 7z file data");
index 7a010ee00f22c0e92857f42ed5ce3de20d6d153c..a22d06ea3838e0f47525a67eb9f487ae7f243baa 100644 (file)
@@ -577,6 +577,9 @@ archive_write_binary_close(struct archive_write *a)
        struct archive_entry *trailer;
 
        trailer = archive_entry_new2(NULL);
+       if (trailer == NULL) {
+               return ARCHIVE_FATAL;
+       }
        /* nlink = 1 here for GNU cpio compat. */
        archive_entry_set_nlink(trailer, 1);
        archive_entry_set_size(trailer, 0);
index 426f779a2b0b5ca47a9705b5bd6bc1d984ac28f0..6dce78b45452e650740b1f707aceaf661e03eae8 100644 (file)
@@ -467,6 +467,9 @@ archive_write_odc_close(struct archive_write *a)
        struct archive_entry *trailer;
 
        trailer = archive_entry_new2(NULL);
+       if (trailer == NULL) {
+               return ARCHIVE_FATAL;
+       }
        /* nlink = 1 here for GNU cpio compat. */
        archive_entry_set_nlink(trailer, 1);
        archive_entry_set_size(trailer, 0);