From ef8a7085e5014662d1ca74bc13e762f5e900bc3f Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 28 Oct 2020 13:03:59 +0100 Subject: Fix: tar2sqfs: if --root-becomes is used, also retarget links In addition to skipping non-prefixed files and stripping the prefix off of entries we accept, the targets of links also have to be altered, since they can be absolute paths with the root prefix attached. This can affect symbolic links as well. Altough they are allowed to point into nowhere, across filesystem boundaries, they may also be absolute paths refering to existing locations in the filesystem, so no distinction is made by default. However, the later may be intended (e.g. only a subdirectory is packed into SquashFS and then mounted at that location), so a command line switch is added to disable symlink retargetting. Signed-off-by: David Oberhollenzer --- bin/tar2sqfs/process_tarball.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'bin/tar2sqfs/process_tarball.c') diff --git a/bin/tar2sqfs/process_tarball.c b/bin/tar2sqfs/process_tarball.c index 7492f27..40a8157 100644 --- a/bin/tar2sqfs/process_tarball.c +++ b/bin/tar2sqfs/process_tarball.c @@ -203,6 +203,7 @@ int process_tarball(istream_t *input_file, sqfs_writer_t *sqfs) sqfs_u64 offset, count; sparse_map_t *m; size_t rootlen; + char *target; int ret; rootlen = root_becomes == NULL ? 0 : strlen(root_becomes); @@ -251,6 +252,26 @@ int process_tarball(istream_t *input_file, sqfs_writer_t *sqfs) stderr); skip = true; } + + if (hdr.link_target != NULL && + (hdr.is_hard_link || !no_symlink_retarget)) { + target = strdup(hdr.link_target); + if (target == NULL) { + fprintf(stderr, "packing '%s': %s\n", + hdr.name, strerror(errno)); + goto fail; + } + + if (canonicalize_name(target) == 0 && + !strncmp(target, root_becomes, rootlen) && + target[rootlen] == '/') { + memmove(hdr.link_target, + target + rootlen, + strlen(target + rootlen) + 1); + } + + free(target); + } } else if (hdr.name[0] == '\0') { is_root = true; } -- cgit v1.2.3