From 0bee51bc51f08c94ff5714249662c10c8c859b87 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 23 Nov 2019 05:08:57 -0600 Subject: Elliott pointed out a codepath that could use uninitialized data. (If DIRTREE_SYMFOLLOW returns ENOENT, skipping the second fstatat() would also skip the else goto error) --- lib/dirtree.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/dirtree.c b/lib/dirtree.c index beaafd59..9917a815 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -38,9 +38,8 @@ struct dirtree *dirtree_add_node(struct dirtree *parent, char *name, int flags) // stat dangling symlinks if (fstatat(fd, name, &st, sym)) { - if (errno != ENOENT - || (!sym && fstatat(fd, name, &st, AT_SYMLINK_NOFOLLOW))) - { + // If we got ENOENT without NOFOLLOW, try again with NOFOLLOW. + if (errno!=ENOENT || sym || fstatat(fd, name, &st, AT_SYMLINK_NOFOLLOW)) { if (flags&DIRTREE_STATLESS) statless++; else goto error; } -- cgit v1.2.3