From 063f57dec14986d1895d83d9113fd1dec7f135f4 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 23 Oct 2019 13:51:01 +0200 Subject: Fix tar2sqfs: check for empty names or './' entrty This commit makes sure entries with empty file names are skipped by tar2sqfs. The case of a directory with the name './' is treated specially, because tar can generate in some common use cases. For instance: $ mkdir foo $ touch foo/bar $ tar -C ./foo -c . > out.tar $ tar tf out.tar will generate a tar file with an entry named './'. For the future it might be interesting to turn that into the root inode somehow. Signed-off-by: David Oberhollenzer --- tar/tar2sqfs.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tar/tar2sqfs.c') diff --git a/tar/tar2sqfs.c b/tar/tar2sqfs.c index 627cae9..30f1abb 100644 --- a/tar/tar2sqfs.c +++ b/tar/tar2sqfs.c @@ -345,12 +345,26 @@ static int process_tar_ball(void) skip = false; + if (hdr.name != NULL && strcmp(hdr.name, "./") == 0 && + S_ISDIR(hdr.sb.st_mode)) { + /* XXX: tar entries might be prefixed with ./ which is + stripped by cannonicalize_name, but the tar file may + contain a directory entry named './' */ + clear_header(&hdr); + continue; + } + if (hdr.name == NULL || canonicalize_name(hdr.name) != 0) { fprintf(stderr, "skipping '%s' (invalid name)\n", hdr.name); skip = true; } + if (hdr.name[0] == '\0') { + fputs("skipping entry with empty name\n", stderr); + skip = true; + } + if (!skip && hdr.unknown_record) { fprintf(stderr, "%s: unknown entry type\n", hdr.name); skip = true; -- cgit v1.2.3