From b30fd4cb656d7a98c12f63fbb225db4e2cb3a776 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 27 Oct 2019 15:24:50 -0500 Subject: Tar extract should delete files or symlinks where it's making a directory, but --restrict checking should run on the path up to the last component before unlinking so tar can't be tricked into deleting random files off the system. --- lib/xwrap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/xwrap.c') diff --git a/lib/xwrap.c b/lib/xwrap.c index 1a3ef837..591c9513 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -525,7 +525,8 @@ void xstat(char *path, struct stat *st) // Canonicalize path, even to file with one or more missing components at end. // Returns allocated string for pathname or NULL if doesn't exist -// exact = 1 file must exist, 0 dir must exist, -1 show theoretical location +// exact = 1 file must exist, 0 dir must exist, -1 show theoretical location, +// -2 don't resolve last file char *xabspath(char *path, int exact) { struct string_list *todo, *done = 0; @@ -570,7 +571,8 @@ char *xabspath(char *path, int exact) } // Is this a symlink? - len = readlinkat(dirfd, new->str, libbuf, sizeof(libbuf)); + if (exact == -2 && !todo) len = 0; + else len = readlinkat(dirfd, new->str, libbuf, sizeof(libbuf)); if (len>4095) goto error; // Not a symlink: add to linked list, move dirfd, fail if error -- cgit v1.2.3