From: Martin Matuska Date: Tue, 9 Jun 2020 05:06:32 +0000 (+0200) Subject: Skip hardlinks pointing to itself and issue a warning X-Git-Tag: v3.5.0~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3073af254a317e46ac058de47c05a55276ea14b;p=thirdparty%2Flibarchive.git Skip hardlinks pointing to itself and issue a warning Fixes #1381 --- diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c index 0168d0d41..2f86222ce 100644 --- a/libarchive/archive_write_disk_posix.c +++ b/libarchive/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