From 9ac39a016817d5bd79992652d537a892a1235b1e Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Fri, 30 May 2025 23:41:21 +0200 Subject: [PATCH] Always check archive_string_ensure return value Memory allocation might fail, so check if it was successful. Signed-off-by: Tobias Stoeckmann --- libarchive/archive_write_set_format_iso9660.c | 7 ++++++- libarchive/archive_write_set_format_mtree.c | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libarchive/archive_write_set_format_iso9660.c b/libarchive/archive_write_set_format_iso9660.c index 3c5b88994..ac36bea31 100644 --- a/libarchive/archive_write_set_format_iso9660.c +++ b/libarchive/archive_write_set_format_iso9660.c @@ -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; diff --git a/libarchive/archive_write_set_format_mtree.c b/libarchive/archive_write_set_format_mtree.c index c2ecc4246..02fbb2d2f 100644 --- a/libarchive/archive_write_set_format_mtree.c +++ b/libarchive/archive_write_set_format_mtree.c @@ -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; -- 2.47.2