From 2c638cd2e2535b5e84c579e843a695fae07dce7b Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 20 Jul 2020 19:28:56 +0200 Subject: [PATCH] Fix unpacking of bindists with hardinks pointing to themselves https://github.com/vmchale/libarchive/issues/14 https://github.com/libarchive/libarchive/issues/1381 --- 3rdparty/libarchive/c/archive_write_disk_posix.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/3rdparty/libarchive/c/archive_write_disk_posix.c b/3rdparty/libarchive/c/archive_write_disk_posix.c index 0168d0d..2f86222 100644 --- a/3rdparty/libarchive/c/archive_write_disk_posix.c +++ b/3rdparty/libarchive/c/archive_write_disk_posix.c @@ -546,6 +546,7 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry) { struct archive_write_disk *a = (struct archive_write_disk *)_a; struct fixup_entry *fe; + const char *linkname; int ret, r; archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, @@ -590,6 +591,17 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry) if (ret != ARCHIVE_OK) return (ret); + /* + * Check if we have a hardlink that points to itself. + */ + linkname = archive_entry_hardlink(a->entry); + if (linkname != NULL && strcmp(a->name, linkname) == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Skipping hardlink pointing to itself: %s", + a->name); + return (ARCHIVE_WARN); + } + /* * Query the umask so we get predictable mode settings. * This gets done on every call to _write_header in case the