Skip to content

Commit

Permalink
bisect: copy filename string obtained from git_path()
Browse files Browse the repository at this point in the history
Prevent the string from being overwritten by other callers of
git_path() and friends before we are done using it.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed May 3, 2012
1 parent 989c0e5 commit 144e709
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ static int check_ancestors(const char *prefix)
*/
static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
{
const char *filename = git_path("BISECT_ANCESTORS_OK");
char *filename = xstrdup(git_path("BISECT_ANCESTORS_OK"));
struct stat st;
int fd;

Expand All @@ -842,11 +842,11 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)

/* Check if file BISECT_ANCESTORS_OK exists. */
if (!stat(filename, &st) && S_ISREG(st.st_mode))
return;
goto done;

/* Bisecting with no good rev is ok. */
if (good_revs.nr == 0)
return;
goto done;

/* Check if all good revs are ancestor of the bad rev. */
if (check_ancestors(prefix))
Expand All @@ -859,6 +859,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
filename, strerror(errno));
else
close(fd);
done:
free(filename);
}

/*
Expand Down

0 comments on commit 144e709

Please sign in to comment.