Skip to content

Commit

Permalink
merge-recursive: use xstrdup() instead of fixed buffer
Browse files Browse the repository at this point in the history
Paths can be longer than PATH_MAX.  Avoid a buffer overrun in
check_dir_renamed() by using xstrdup() to make a private copy safely.

Signed-off-by: Rene Scharfe <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
rscharfe authored and gitster committed Jun 18, 2018
1 parent 1de70db commit 94eff2b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions merge-recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,18 +2017,18 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs,
static struct dir_rename_entry *check_dir_renamed(const char *path,
struct hashmap *dir_renames)
{
char temp[PATH_MAX];
char *temp = xstrdup(path);
char *end;
struct dir_rename_entry *entry;
struct dir_rename_entry *entry = NULL;;

strcpy(temp, path);
while ((end = strrchr(temp, '/'))) {
*end = '\0';
entry = dir_rename_find_entry(dir_renames, temp);
if (entry)
return entry;
break;
}
return NULL;
free(temp);
return entry;
}

static void compute_collisions(struct hashmap *collisions,
Expand Down

0 comments on commit 94eff2b

Please sign in to comment.