]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
fix output format handling and symlink detection for PWB
authorTom Ivar Helbekkmo <tih@hamartun.priv.no>
Sat, 6 Mar 2021 09:09:53 +0000 (10:09 +0100)
committerTom Ivar Helbekkmo <tih@hamartun.priv.no>
Sat, 6 Mar 2021 09:09:53 +0000 (10:09 +0100)
cpio/cpio.c
libarchive/archive_write_set_format_cpio_binary.c

index d80c762175a2943a39af6abf8e3fb1be21e31f8c..3c1caeea1a6dc1017a4b49db3d59c0937d7f1499 100644 (file)
@@ -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':
index 3f608c713a17b21f02b0c5ba19791171742bc25d..c1e2f65aa94a79472a402aacd7b8f1bb65e46395 100644 (file)
@@ -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);