Skip to content

Commit 94eff2b

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 1de70db commit 94eff2b

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
@@ -2017,18 +2017,18 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs,
20172017
static struct dir_rename_entry *check_dir_renamed(const char *path,
20182018
struct hashmap *dir_renames)
20192019
{
2020-
char temp[PATH_MAX];
2020+
char *temp = xstrdup(path);
20212021
char *end;
2022-
struct dir_rename_entry *entry;
2022+
struct dir_rename_entry *entry = NULL;;
20232023

2024-
strcpy(temp, path);
20252024
while ((end = strrchr(temp, '/'))) {
20262025
*end = '\0';
20272026
entry = dir_rename_find_entry(dir_renames, temp);
20282027
if (entry)
2029-
return entry;
2028+
break;
20302029
}
2031-
return NULL;
2030+
free(temp);
2031+
return entry;
20322032
}
20332033

20342034
static void compute_collisions(struct hashmap *collisions,

0 commit comments

Comments
 (0)