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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jun 10, 2018 at 12:56 UTC
94eff2b69a3dc662edac9984a08241d033e764d7
1 file changed
+5
-5
merge-recursive.c
+5
-5
@@ -2017,18 +2017,18 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs,
2017
static struct dir_rename_entry *check_dir_renamed(const char *path,
2018
struct hashmap *dir_renames)
2019
{
2020
- char temp[PATH_MAX];
2020
+ char *temp = xstrdup(path);
2021
char *end;
2022
- struct dir_rename_entry *entry;
2022
+ struct dir_rename_entry *entry = NULL;;
2023
2024
- strcpy(temp, path);
2024
while ((end = strrchr(temp, '/'))) {
2025
*end = '\0';
2026
entry = dir_rename_find_entry(dir_renames, temp);
2027
if (entry)
2029
- return entry;
2028
+ break;
2029
}
2031
- return NULL;
2030
+ free(temp);
2031
+ return entry;
2032
}
2033
2034
static void compute_collisions(struct hashmap *collisions,