]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-recursive: use xstrdup() instead of fixed buffer
authorRené Scharfe <l.s.r@web.de>
Sun, 10 Jun 2018 10:56:31 +0000 (12:56 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 18 Jun 2018 17:03:38 +0000 (10:03 -0700)
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>
merge-recursive.c

index 13b47629719022c0e5d1311a1c7c3cd905936700..16d2377b71bf40ae88fa5ffd5863105a40e6c96b 100644 (file)
@@ -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,