Skip to content

Commit

Permalink
status: fix for old-style submodules with commondir
Browse files Browse the repository at this point in the history
In f9b7573 (repository: free fields before overwriting them,
2017-09-05), Git was taught to release memory before overwriting it, but
357a03e (repository.c: move env-related setup code back to
environment.c, 2018-03-03) changed the code so that it would not
_always_ be overwritten.

As a consequence, the `commondir` attribute would point to
already-free()d memory.

This seems not to cause problems in core Git, but there are add-on
patches in Git for Windows where the `commondir` attribute is
subsequently used and causing invalid memory accesses e.g. in setups
containing old-style submodules (i.e. the ones with a `.git` directory
within theirs worktrees) that have `commondir` configured.

This fixes #4083.

Signed-off-by: Andrey Zabavnikov <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
sceptical-coder authored and Git for Windows Build Agent committed Oct 22, 2024
1 parent 3b9efdd commit 5222d94
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static void repo_set_commondir(struct repository *repo,
{
struct strbuf sb = STRBUF_INIT;

free(repo->commondir);
FREE_AND_NULL(repo->commondir);

if (commondir) {
repo->different_commondir = 1;
Expand Down

0 comments on commit 5222d94

Please sign in to comment.