]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
shar: Check strdup return value (#2173)
authorTobias Stoeckmann <stoeckmann@users.noreply.github.com>
Thu, 9 May 2024 23:49:50 +0000 (01:49 +0200)
committerGitHub <noreply@github.com>
Thu, 9 May 2024 23:49:50 +0000 (01:49 +0200)
The strdup function could fail, so check for NULL return value.

libarchive/archive_write_set_format_shar.c

index 52ea6adc2264a0848dbd7310a368e3d722a7d2ba..da2bc0ca3edb3d11806bcda9b561a57d5ec6cee2 100644 (file)
@@ -209,6 +209,10 @@ archive_write_shar_header(struct archive_write *a, struct archive_entry *entry)
        if (archive_entry_filetype(entry) != AE_IFDIR) {
                /* Try to create the dir. */
                p = strdup(name);
+               if (p == NULL) {
+                       archive_set_error(&a->archive, ENOMEM, "Out of memory");
+                       return (ARCHIVE_FATAL);
+               }
                pp = strrchr(p, '/');
                /* If there is a / character, try to create the dir. */
                if (pp != NULL) {
@@ -291,6 +295,10 @@ archive_write_shar_header(struct archive_write *a, struct archive_entry *entry)
                        free(shar->last_dir);
 
                        shar->last_dir = strdup(name);
+                       if (shar->last_dir == NULL) {
+                               archive_set_error(&a->archive, ENOMEM, "Out of memory");
+                               return (ARCHIVE_FATAL);
+                       }
                        /* Trim a trailing '/'. */
                        pp = strrchr(shar->last_dir, '/');
                        if (pp != NULL && pp[1] == '\0')