summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-11-21 18:05:36 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-11-21 18:05:36 -0500
commitfae757c2d7ba933b3db3cfae6c871846b4d1870f (patch)
tree8f3bd18052cbe5e09a8bb8de6724f53c48af621d /bftw.c
parent9b5342ef493521d42953e5f26ea88b58973c6c6a (diff)
downloadbfs-fae757c2d7ba933b3db3cfae6c871846b4d1870f.tar.xz
bftw: Make a defensive copy of the ftwbuf
The callback may modify the ftwbuf, but we check it after the callback (for typeflag and statbuf). Have them mutate a copy instead.
Diffstat (limited to 'bftw.c')
-rw-r--r--bftw.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/bftw.c b/bftw.c
index cbc9a1b..0cf5c49 100644
--- a/bftw.c
+++ b/bftw.c
@@ -841,7 +841,10 @@ static int bftw_handle_path(struct bftw_state *state) {
return BFTW_FAIL;
}
- enum bftw_action action = state->fn(&state->ftwbuf, state->ptr);
+ // Defensive copy
+ struct BFTW ftwbuf = state->ftwbuf;
+
+ enum bftw_action action = state->fn(&ftwbuf, state->ptr);
switch (action) {
case BFTW_CONTINUE:
case BFTW_SKIP_SIBLINGS: