]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Always check archive_string_ensure return value 2651/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 30 May 2025 21:41:21 +0000 (23:41 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 30 May 2025 21:42:40 +0000 (23:42 +0200)
Memory allocation might fail, so check if it was successful.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/archive_write_set_format_iso9660.c
libarchive/archive_write_set_format_mtree.c

index 3c5b8899434ebd7c5008da6866edb99a72bbb979..ac36bea31e89985420bd51878ce28958dd58c392 100644 (file)
@@ -1167,7 +1167,12 @@ archive_write_set_format_iso9660(struct archive *_a)
        iso9660->primary.rootent->parent = iso9660->primary.rootent;
        iso9660->cur_dirent = iso9660->primary.rootent;
        archive_string_init(&(iso9660->cur_dirstr));
-       archive_string_ensure(&(iso9660->cur_dirstr), 1);
+       if (archive_string_ensure(&(iso9660->cur_dirstr), 1) == NULL) {
+               free(iso9660);
+               archive_set_error(&a->archive, ENOMEM,
+                   "Can't allocate memory");
+               return (ARCHIVE_FATAL);
+       }
        iso9660->cur_dirstr.s[0] = 0;
        iso9660->sconv_to_utf16be = NULL;
        iso9660->sconv_from_utf16be = NULL;
index c2ecc424675b49e8443e17f23eeb3ff880c7152a..02fbb2d2f5558167049f7a408a6bb3897f8b833c 100644 (file)
@@ -2209,9 +2209,13 @@ mtree_entry_tree_add(struct archive_write *a, struct mtree_entry **filep)
                 * inserted. */
                mtree->cur_dirent = dent;
                archive_string_empty(&(mtree->cur_dirstr));
-               archive_string_ensure(&(mtree->cur_dirstr),
+               if (archive_string_ensure(&(mtree->cur_dirstr),
                    archive_strlen(&(dent->parentdir)) +
-                   archive_strlen(&(dent->basename)) + 2);
+                   archive_strlen(&(dent->basename)) + 2) == NULL) {
+                       archive_set_error(&a->archive, ENOMEM,
+                           "Can't allocate memory");
+                       return (ARCHIVE_FATAL);
+               }
                if (archive_strlen(&(dent->parentdir)) +
                    archive_strlen(&(dent->basename)) == 0)
                        mtree->cur_dirstr.s[0] = 0;