diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2021-10-19 12:11:11 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2021-10-19 12:28:17 -0400 |
commit | be3c3ed7dfd0182ea11468c8d4dffa465ce7a44f (patch) | |
tree | 102bf8293b1dc684c2777fc1f9a6bacdb05bea06 /parse.c | |
parent | 32c54e2769c3e4c5ada44e6107745d0893e86c70 (diff) | |
download | bfs-be3c3ed7dfd0182ea11468c8d4dffa465ce7a44f.tar.xz |
parse: Fix UAF + double-free when ftruncate() fails
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -336,6 +336,7 @@ static int expr_open(struct parser_state *state, struct expr *expr, const char * FILE *file = NULL; CFILE *cfile = NULL; + CFILE *dedup = NULL; file = xfopen(path, O_WRONLY | O_CREAT | O_CLOEXEC); if (!file) { @@ -347,7 +348,7 @@ static int expr_open(struct parser_state *state, struct expr *expr, const char * goto fail; } - CFILE *dedup = bfs_ctx_dedup(ctx, cfile, path); + dedup = bfs_ctx_dedup(ctx, cfile, path); if (!dedup) { goto fail; } @@ -367,10 +368,12 @@ static int expr_open(struct parser_state *state, struct expr *expr, const char * fail: parse_error(state, "${blu}%s${rs} ${bld}%s${rs}: %m.\n", expr->argv[0], path); - if (cfile) { - cfclose(cfile); - } else if (file) { - fclose(file); + if (!dedup) { + if (cfile) { + cfclose(cfile); + } else if (file) { + fclose(file); + } } return -1; } |