Skip to content

Commit 4d0984b

Browse files
peffgitster
authored andcommitted
fsck: do not reuse child_process structs
The run-command API makes no promises about what is left in a struct child_process after a command finishes, and it's not safe to simply reuse it again for a similar command. In particular: - if you use child->args or child->env_array, they are cleared after finish_command() - likewise, start_command() may point child->argv at child->args->argv; reusing that would lead to accessing freed memory - the in/out/err may hold pipe descriptors from the previous run These two calls are _probably_ OK because they do not use any of those features. But it's only by chance, and may break in the future; let's reinitialize our struct for each program we run. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8858448 commit 4d0984b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

builtin/fsck.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,9 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
841841

842842
prepare_alt_odb(the_repository);
843843
for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
844+
child_process_init(&commit_graph_verify);
845+
commit_graph_verify.argv = verify_argv;
846+
commit_graph_verify.git_cmd = 1;
844847
verify_argv[2] = "--object-dir";
845848
verify_argv[3] = alt->path;
846849
if (run_command(&commit_graph_verify))
@@ -859,6 +862,9 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
859862

860863
prepare_alt_odb(the_repository);
861864
for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
865+
child_process_init(&midx_verify);
866+
midx_verify.argv = midx_argv;
867+
midx_verify.git_cmd = 1;
862868
midx_argv[2] = "--object-dir";
863869
midx_argv[3] = alt->path;
864870
if (run_command(&midx_verify))

0 commit comments

Comments
 (0)