From 9b5342ef493521d42953e5f26ea88b58973c6c6a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 21 Nov 2016 17:35:27 -0500 Subject: bftw: Always initialize dircache_entry::{dev,ino} If stat() fails, they won't get filled in otherwise. Then cycle detection would have read uninitialized values. --- bftw.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'bftw.c') diff --git a/bftw.c b/bftw.c index ea683be..cbc9a1b 100644 --- a/bftw.c +++ b/bftw.c @@ -222,6 +222,9 @@ static struct dircache_entry *dircache_add(struct dircache *cache, struct dircac entry->refcount = 1; entry->fd = -1; + entry->dev = -1; + entry->ino = -1; + memcpy(entry->name, name, namelen); if (needs_slash) { entry->name[namelen++] = '/'; @@ -861,12 +864,10 @@ static struct dircache_entry *bftw_add(struct bftw_state *state, const char *nam return NULL; } - if (state->flags & (BFTW_DETECT_CYCLES | BFTW_XDEV)) { - const struct stat *statbuf = state->ftwbuf.statbuf; - if (statbuf) { - entry->dev = statbuf->st_dev; - entry->ino = statbuf->st_ino; - } + const struct stat *statbuf = state->ftwbuf.statbuf; + if (statbuf) { + entry->dev = statbuf->st_dev; + entry->ino = statbuf->st_ino; } return entry; -- cgit v1.2.3