Skip to content

Commit bd22d9b

Browse files
authored
dtar: fix creation with symlink and --preserve-* (#629)
Fix creation of corrupted archive with symlink when --preserve-{xattrs,acl,flags} command line option is used. When it is provided a valid file descriptor, libarchive archive_read_disk_entry_from_file() calls fstat() which follows symlinks. This commit introduces an exception for symlinks to not provide a file descriptor to archive_read_disk_entry_from_file() which makes it call lstat() on entry path and create a valid symlink archive entry eventually. fix #628 Signed-off-by: Rémi Palancher <[email protected]>
1 parent 412545e commit bd22d9b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/common/mfu_flist_archive.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,17 @@ static int encode_header(
427427
}
428428
archive_read_disk_set_behavior(source, flags);
429429

430-
/* build the entry by querying the item associated with the open file descriptor */
430+
/* build the entry by querying the item associated with the open
431+
* file descriptor, on which libarchive calls fstat(). For symlinks,
432+
* ignore this file description to make libarchive() call lstat() on
433+
* the file instead and define a symlink entry eventually.
434+
*/
435+
mfu_filetype type = mfu_flist_file_get_type(flist, idx);
436+
if (type == MFU_TYPE_LINK) {
437+
mfu_close(fname, fd);
438+
fd = -1;
439+
}
440+
431441
int r = archive_read_disk_entry_from_file(source, entry, fd, NULL);
432442
if (r != ARCHIVE_OK) {
433443
MFU_LOG(MFU_LOG_ERR, "Failed to define entry for '%s': archive_read_disk_entry_from_file(): %s",

0 commit comments

Comments
 (0)