From d12dff713a2e35865857e8cd2c3dec71222ab3cc Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Wed, 22 Feb 2006 11:13:07 +0000 Subject: [PATCH] If opendir(".") fails after descending into a subdirectory via chdir(), be sure to undo the effects of the chdir before continuing. Without this, after hitting a directory with mode 0111 (for example), tar will get lost, and won't add any yet unvisted files to your archive. (Or possibly add the wrong files, I suppose...) Reviewed By: kientzle@ --- usr.bin/tar/tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usr.bin/tar/tree.c b/usr.bin/tar/tree.c index 4528eea3c15b..944a787bcf47 100644 --- a/usr.bin/tar/tree.c +++ b/usr.bin/tar/tree.c @@ -311,13 +311,14 @@ tree_next(struct tree *t) t->tree_errno = errno; return (t->visit_type = TREE_ERROR_DIR); } + t->depth++; t->d = opendir("."); if (t->d == NULL) { + tree_ascend(t); /* Undo "chdir" */ tree_pop(t); t->tree_errno = errno; return (t->visit_type = TREE_ERROR_DIR); } - t->depth++; t->flags &= ~hasLstat; t->flags &= ~hasStat; t->basename = ".";