From fae757c2d7ba933b3db3cfae6c871846b4d1870f Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 21 Nov 2016 18:05:36 -0500 Subject: 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. --- bftw.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'bftw.c') 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: -- cgit v1.2.3