From e21bf0b60c1b9d67fe7553105b6440c3fce7c0bb Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 7 Oct 2019 15:54:41 +0200 Subject: Do an explicit "is filename sane" check Until now, filenames containing '/' or being equal to '..' or '.' where not handled explicitly, because they are canonicalized later, which will then fail. This commit adds an explicit check to make those fail immediately with a clear, specific error message. Signed-off-by: David Oberhollenzer --- tar/sqfs2tar.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tar') diff --git a/tar/sqfs2tar.c b/tar/sqfs2tar.c index 3e64b45..1e05cd4 100644 --- a/tar/sqfs2tar.c +++ b/tar/sqfs2tar.c @@ -266,6 +266,16 @@ static int write_tree_dfs(const sqfs_tree_node_t *n) if (n->parent == NULL && S_ISDIR(n->inode->base.mode)) goto skip_hdr; + if (!is_filename_sane((const char *)n->name)) { + fprintf(stderr, "Found a file named '%s', skipping.\n", + n->name); + if (dont_skip) { + fputs("Not allowed to skip files, aborting!\n", stderr); + return -1; + } + return 0; + } + name = sqfs_tree_node_get_path(n); if (name == NULL) { perror("resolving tree node path"); -- cgit v1.2.3