[Toybox] [PATCH] tar: Fix support for long symbolic links

enh enh at google.com
Wed Mar 20 17:44:50 PDT 2019


in case you're curious, the copy of this that was uploaded to AOSP
(https://android-review.googlesource.com/c/platform/external/toybox/+/931533)
also included the motivation:

  We need this to run the tar command that can be found at
https://01.org/linuxgraphics/gfx-docs/drm/dev-tools/gcov.html#appendix-b-gather-on-test-sh

  When we enable gcov in the kernel, it creates symlinks in debugfs
with very long target names.

  lrwxrwxrwx 1 root root 0 1970-01-01 00:00
/d/gcov/usr/local/google/home/d/a/k/p-dev-msm-bluecross-4.9/out/android-msm-bluecross-4.9/private/msm-google/kernel/smpboot.gcno
-> /usr/local/google/home/d/a/k/p-dev-msm-bluecross-4.9/out/android-msm-bluecross-4.9/private/msm-google/kernel/.tmp_smpboot.gcno

(iirc you were looking for some real-world examples of long names...)

On Tue, Mar 19, 2019 at 4:38 PM Daniel Mentz <danielmentz at google.com> wrote:
>
> Similar to commit 28711d30 ("toybox: tar: Fix support for long names"),
> fix the handling of symbolic links with target names longer than 100
> characters.
>
> For target names longer than 100 characters, we store the first 100
> characters in the link field, and the function write_longname() takes
> care of storing the complete target name. The strncpy() function is the
> right tool for this copy operation. Previously, xstrncpy() has been used
> which called error_exit() in cases where the target name was longer than
> 100 characters. However, a truncated or non-null-terminated string is
> not a concern, because the tar program handles this situation correctly
> while reading tar archives.
>
> Previously, we saw the following error message:
>
> tar: '<name of long target>' > 100 bytes
> ---
>  toys/pending/tar.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/toys/pending/tar.c b/toys/pending/tar.c
> index 97e699b4..8683fc35 100644
> --- a/toys/pending/tar.c
> +++ b/toys/pending/tar.c
> @@ -209,11 +209,9 @@ static void add_file(char **nam, struct stat *st)
>  // TODO: test preserve symlink ownership
>      hdr.type = '1'+i;
>      if (!(lnk = i ? xreadlink(name) : node->arg)) return perror_msg("readlink");
> -// TODO: does this need NUL terminator?
>      if (strlen(lnk) > sizeof(hdr.link))
>        write_longname(lnk, 'K'); //write longname LINK
> -// TODO: this will error_exit() if too long, not truncate.
> -    xstrncpy(hdr.link, lnk, sizeof(hdr.link));
> +    strncpy(hdr.link, lnk, sizeof(hdr.link));
>      if (i) free(lnk);
>    } else if (S_ISREG(st->st_mode)) {
>      hdr.type = '0';
> --
> 2.21.0.225.g810b269d1ac-goog
>



More information about the Toybox mailing list