summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-10-19 15:30:48 -0400
committerTavian Barnes <tavianator@tavianator.com>2022-10-19 15:30:48 -0400
commit4ec966263444dfae8837cd73b980cfdb9aabd93f (patch)
tree618b59786b4fc77c7d718f366d65a1d66c6004af /src
parent9192487a267f7052924db88d88cf381513c773d2 (diff)
downloadbfs-4ec966263444dfae8837cd73b980cfdb9aabd93f.tar.xz
parse: Don't free uninitialized data on error paths
Diffstat (limited to 'src')
-rw-r--r--src/parse.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/parse.c b/src/parse.c
index fbb095d..15feac1 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -136,6 +136,19 @@ struct bfs_expr *bfs_expr_new(bfs_eval_fn *eval_fn, size_t argc, char **argv) {
expr->successes = 0;
expr->elapsed.tv_sec = 0;
expr->elapsed.tv_nsec = 0;
+
+ // Prevent bfs_expr_free() from freeing uninitialized pointers on error paths
+ if (bfs_expr_has_children(expr)) {
+ expr->lhs = NULL;
+ expr->rhs = NULL;
+ } else if (eval_fn == eval_exec) {
+ expr->exec = NULL;
+ } else if (eval_fn == eval_fprintf) {
+ expr->printf = NULL;
+ } else if (eval_fn == eval_regex) {
+ expr->regex = NULL;
+ }
+
return expr;
}