From: Tom Ivar Helbekkmo Date: Sat, 6 Mar 2021 09:09:53 +0000 (+0100) Subject: fix output format handling and symlink detection for PWB X-Git-Tag: v3.5.2~18^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=809c2e466faa4ec6e60c6bf3f9b2a95dd2f6e4fc;p=thirdparty%2Flibarchive.git fix output format handling and symlink detection for PWB --- diff --git a/cpio/cpio.c b/cpio/cpio.c index d80c76217..3c1caeea1 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -194,7 +194,6 @@ main(int argc, char *argv[]) break; case '6': /* in/out: assume/create 6th edition (PWB) format */ cpio->option_pwb = 1; - cpio->format = "pwb"; break; case '7': /* out: create archive using 7th Edition binary format */ cpio->format = "bin"; @@ -407,9 +406,12 @@ main(int argc, char *argv[]) switch (cpio->mode) { case 'o': - if (cpio->format == NULL) - cpio->format = "cpio"; /* Default format */ - + if (cpio->format == NULL) { + if (cpio->option_pwb) + cpio->format = "pwb"; + else + cpio->format = "cpio"; + } mode_out(cpio); break; case 'i': diff --git a/libarchive/archive_write_set_format_cpio_binary.c b/libarchive/archive_write_set_format_cpio_binary.c index 3f608c713..c1e2f65aa 100644 --- a/libarchive/archive_write_set_format_cpio_binary.c +++ b/libarchive/archive_write_set_format_cpio_binary.c @@ -446,13 +446,19 @@ write_header(struct archive_write *a, struct archive_entry *entry) h.h_mode = archive_entry_mode(entry); if (((h.h_mode & AE_IFMT) == AE_IFSOCK) || ((h.h_mode & AE_IFMT) == AE_IFIFO)) { archive_set_error(&a->archive, EINVAL, - "sockets and fifos cannot be represented in the binary cpio format"); + "sockets and fifos cannot be represented in the binary cpio formats"); ret_final = ARCHIVE_FATAL; goto exit_write_header; } if (a->archive.archive_format == ARCHIVE_FORMAT_CPIO_PWB) { - if (((h.h_mode & AE_IFMT) == AE_IFLNK) || ((h.h_mode & AE_IFMT) == AE_IFREG)) - h.h_mode &= (~AE_IFMT); + if ((h.h_mode & AE_IFMT) == AE_IFLNK) { + archive_set_error(&a->archive, EINVAL, + "symbolic links cannot be represented in the PWB cpio format"); + ret_final = ARCHIVE_FATAL; + goto exit_write_header; + } + /* we could turn off AE_IFREG here, but it does no harm, */ + /* and allows v7 cpio to read the entry without confusion */ } h.h_mode = swap16(h.h_mode);