summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2007-03-03 07:49:08 +0000
committerkientzle <kientzle@FreeBSD.org>2007-03-03 07:49:08 +0000
commitfc9e336ec574dce854d86a8aa4f42e42bea5cefc (patch)
treeb26227aa4392bb49dbcc31d382433ec625b8ddc1 /usr.bin
parent1a60578adb6be1f7da9ed95f38cf52c20be13591 (diff)
downloadFreeBSD-src-fc9e336ec574dce854d86a8aa4f42e42bea5cefc.zip
FreeBSD-src-fc9e336ec574dce854d86a8aa4f42e42bea5cefc.tar.gz
Make the file tests robust against broken symlinks and other
sources of stat()/lstat() failure.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tar/tree.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/usr.bin/tar/tree.c b/usr.bin/tar/tree.c
index 8bf413c..246352e 100644
--- a/usr.bin/tar/tree.c
+++ b/usr.bin/tar/tree.c
@@ -398,6 +398,8 @@ tree_current_lstat(struct tree *t)
int
tree_current_is_dir(struct tree *t)
{
+ const struct stat *st;
+
/*
* If we already have lstat() info, then try some
* cheap tests to determine if this is a dir.
@@ -416,8 +418,12 @@ tree_current_is_dir(struct tree *t)
*/
}
+ st = tree_current_stat(t);
+ /* If we can't stat it, it's not a dir. */
+ if (st == NULL)
+ return 0;
/* Use the definitive test. Hopefully this is cached. */
- return (S_ISDIR(tree_current_stat(t)->st_mode));
+ return (S_ISDIR(st->st_mode));
}
/*
@@ -428,6 +434,7 @@ tree_current_is_dir(struct tree *t)
int
tree_current_is_physical_dir(struct tree *t)
{
+ const struct stat *st;
/*
* If stat() says it isn't a dir, then it's not a dir.
@@ -444,8 +451,12 @@ tree_current_is_physical_dir(struct tree *t)
* hopefully is already cached.
*/
+ st = tree_current_lstat(t);
+ /* If we can't stat it, it's not a dir. */
+ if (st == NULL)
+ return 0;
/* Use the definitive test. Hopefully this is cached. */
- return (S_ISDIR(tree_current_lstat(t)->st_mode));
+ return (S_ISDIR(st->st_mode));
}
/*
@@ -454,7 +465,10 @@ tree_current_is_physical_dir(struct tree *t)
int
tree_current_is_physical_link(struct tree *t)
{
- return (S_ISLNK(tree_current_lstat(t)->st_mode));
+ const struct stat *st = tree_current_lstat(t);
+ if (st == NULL)
+ return 0;
+ return (S_ISLNK(st->st_mode));
}
/*
OpenPOWER on IntegriCloud