Skip to content

Commit 9da2d03

Browse files
rscharfegitster
authored andcommitted
merge-recursive: use xstrdup() instead of fixed buffer
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]>
1 parent c5b761f commit 9da2d03

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

merge-recursive.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,18 +1938,18 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs,
19381938
static struct dir_rename_entry *check_dir_renamed(const char *path,
19391939
struct hashmap *dir_renames)
19401940
{
1941-
char temp[PATH_MAX];
1941+
char *temp = xstrdup(path);
19421942
char *end;
1943-
struct dir_rename_entry *entry;
1943+
struct dir_rename_entry *entry = NULL;;
19441944

1945-
strcpy(temp, path);
19461945
while ((end = strrchr(temp, '/'))) {
19471946
*end = '\0';
19481947
entry = dir_rename_find_entry(dir_renames, temp);
19491948
if (entry)
1950-
return entry;
1949+
break;
19511950
}
1952-
return NULL;
1951+
free(temp);
1952+
return entry;
19531953
}
19541954

19551955
static void compute_collisions(struct hashmap *collisions,

0 commit comments

Comments
 (0)