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 9da2d0379ea0220dd670d70b8af571a2a09b3c12
1 file changed +5 -5
merge-recursive.c
+5 -5
@@ -1938,18 +1938,18 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs,
1938 static struct dir_rename_entry *check_dir_renamed(const char *path,
1939 struct hashmap *dir_renames)
1940 {
1941 - char temp[PATH_MAX];
1941 + char *temp = xstrdup(path);
1942 char *end;
1943 - struct dir_rename_entry *entry;
1943 + struct dir_rename_entry *entry = NULL;;
1944
1945 - strcpy(temp, path);
1945 while ((end = strrchr(temp, '/'))) {
1946 *end = '\0';
1947 entry = dir_rename_find_entry(dir_renames, temp);
1948 if (entry)
1950 - return entry;
1949 + break;
1950 }
1952 - return NULL;
1951 + free(temp);
1952 + return entry;
1953 }
1954
1955 static void compute_collisions(struct hashmap *collisions,