Skip to content

Commit ccef2bb

Browse files
chriscoolgitster
authored andcommitted
read-cache: avoid using git_path() in freshen_shared_index()
When performing an interactive rebase in split-index mode, the commit message that one should rework when squashing commits can contain some garbage instead of the usual concatenation of both of the commit messages. The code uses git_path() to compute the shared index filename, and passes it to check_and_freshen_file() as its argument; there is no guarantee that the rotating pathname buffer passed as argument will stay valid during the life of this call. Make our own copy before calling the function and pass the copy as its argument to avoid this risky pattern. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b460139 commit ccef2bb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

read-cache.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,9 +1690,10 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
16901690
*/
16911691
static void freshen_shared_index(char *base_sha1_hex, int warn)
16921692
{
1693-
const char *shared_index = git_path("sharedindex.%s", base_sha1_hex);
1693+
char *shared_index = git_pathdup("sharedindex.%s", base_sha1_hex);
16941694
if (!check_and_freshen_file(shared_index, 1) && warn)
16951695
warning("could not freshen shared index '%s'", shared_index);
1696+
free(shared_index);
16961697
}
16971698

16981699
int read_index_from(struct index_state *istate, const char *path)

0 commit comments

Comments
 (0)