aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-08-30 15:30:34 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-08-30 17:02:39 +0200
commitc7a7652725f1b0de08b0faeef24d8098c6ee44c0 (patch)
tree2040c77018ccb64921cfebdd5254a5bee19d54ca /src/libutil
parent0b6bff5455aa5a3371c3a5678dbc8cf867fce515 (diff)
Don't segfault if archive_entry_pathname() returns null
Issues #4499.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/tarfile.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libutil/tarfile.cc b/src/libutil/tarfile.cc
index 24905130d..38b4919dc 100644
--- a/src/libutil/tarfile.cc
+++ b/src/libutil/tarfile.cc
@@ -87,13 +87,16 @@ static void extract_archive(TarArchive & archive, const Path & destDir)
struct archive_entry * entry;
int r = archive_read_next_header(archive.archive, &entry);
if (r == ARCHIVE_EOF) break;
- else if (r == ARCHIVE_WARN)
+ auto name = archive_entry_pathname(entry);
+ if (!name)
+ throw Error("cannot get archive member name: %s", archive_error_string(archive.archive));
+ if (r == ARCHIVE_WARN)
warn(archive_error_string(archive.archive));
else
archive.check(r);
archive_entry_set_pathname(entry,
- (destDir + "/" + archive_entry_pathname(entry)).c_str());
+ (destDir + "/" + name).c_str());
archive.check(archive_read_extract(archive.archive, entry, flags));
}