From 7e0467e79d9d4e561adc6c844e8ef481d8a6a7cc Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 7 Jan 2024 12:33:47 -0500 Subject: eval: Check for xbasename() allocation failure --- src/eval.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/eval.c') diff --git a/src/eval.c b/src/eval.c index 49c4aff..130b366 100644 --- a/src/eval.c +++ b/src/eval.c @@ -591,6 +591,7 @@ done: * -i?name test. */ bool eval_name(const struct bfs_expr *expr, struct bfs_eval *state) { + bool ret = false; const struct BFTW *ftwbuf = state->ftwbuf; const char *name = ftwbuf->path + ftwbuf->nameoff; @@ -599,9 +600,15 @@ bool eval_name(const struct bfs_expr *expr, struct bfs_eval *state) { // Any trailing slashes are not part of the name. This can only // happen for the root path. name = copy = xbasename(name); + if (!name) { + eval_report_error(state); + goto done; + } } - bool ret = eval_fnmatch(expr, name); + ret = eval_fnmatch(expr, name); + +done: free(copy); return ret; } -- cgit v1.2.3