Skip to content

Commit 991d549

Browse files
peffgitster
authored andcommitted
commit-graph: delay base_graph assignment in add_graph_to_chain()
When adding a graph to a chain, we do some consistency checks and then if everything looks good, set g->base_graph to add a link to the chain. But when we added a new consistency check in 209250e (commit-graph.c: prevent overflow in add_graph_to_chain(), 2023-07-12), it comes _after_ we've already set g->base_graph. So we might return failure, even though we actually added to the chain. This hasn't caused a bug yet, because after failing to add to the chain, we discard the failed graph struct completely, leaking it. But in order to fix that, it's important that the struct be in a consistent and predictable state after the failure. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 09a75ab commit 991d549

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

commit-graph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,6 @@ static int add_graph_to_chain(struct commit_graph *g,
498498
cur_g = cur_g->base_graph;
499499
}
500500

501-
g->base_graph = chain;
502-
503501
if (chain) {
504502
if (unsigned_add_overflows(chain->num_commits,
505503
chain->num_commits_in_base)) {
@@ -510,6 +508,8 @@ static int add_graph_to_chain(struct commit_graph *g,
510508
g->num_commits_in_base = chain->num_commits + chain->num_commits_in_base;
511509
}
512510

511+
g->base_graph = chain;
512+
513513
return 1;
514514
}
515515

0 commit comments

Comments
 (0)