Skip to content

Commit c607410

Browse files
dschogitster
authored andcommitted
fetch: carefully clear local variable's address after use
As pointed out by CodeQL, it is a potentially dangerous practice to store local variables' addresses in non-local structs. Yet this is exactly what happens with the `acked_commits` attribute that is used in `cmd_fetch()`: The pointer to a local variable is assigned to it. Now, it is Git's convention that `cmd_*()` functions are essentially only returning just before exiting the process, therefore there is little danger that this attribute is used after the code flow returns from that function. However, code in `cmd_*()` function is often so useful that it gets lifted into a library function, at which point this issue could become a real problem. Let's make sure to clear the `acked_commits` attribute out after it was used, and before the function returns (at which point the address would go stale). Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 131a8fa commit c607410

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

builtin/fetch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,7 @@ int cmd_fetch(int argc,
25602560
if (server_options.nr)
25612561
gtransport->server_options = &server_options;
25622562
result = transport_fetch_refs(gtransport, NULL);
2563+
gtransport->smart_options->acked_commits = NULL;
25632564

25642565
oidset_iter_init(&acked_commits, &iter);
25652566
while ((oid = oidset_iter_next(&iter)))

0 commit comments

Comments
 (0)