blame: fix memory corruption scrambling revision name in error message
authorSZEDER Gábor <szeder.dev@gmail.com>
Mon, 24 Jul 2017 21:15:50 +0000 (23:15 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Jul 2017 21:38:02 +0000 (14:38 -0700)
When attempting to blame a non-existing path, git should show an error
message like this:

$ git blame e83c51633 -- nonexisting-file
fatal: no such path nonexisting-file in e83c51633

Since the recent commit 835c49f7d (blame: rework methods that
determine 'final' commit, 2017-05-24) the revision name is either
missing or some scrambled characters are shown instead. The reason is
that the revision name must be duplicated, because it is invalidated
when the pending objects array is cleared in the meantime, but this
commit dropped the duplication.

Restore the duplication of the revision name in the affected functions
(find_single_final() and find_single_initial()).

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
blame.c
diff --git a/blame.c b/blame.c
index 00404b973831c85e111225d641d987d09e96eb5c..07f9b75ccef69f5fc9159998e7caf958dd7d998e 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -1664,7 +1664,7 @@ static struct commit *find_single_final(struct rev_info *revs,
                name = revs->pending.objects[i].name;
        }
        if (name_p)
-               *name_p = name;
+               *name_p = xstrdup_or_null(name);
        return found;
 }
 
@@ -1736,7 +1736,7 @@ static struct commit *find_single_initial(struct rev_info *revs,
                die("No commit to dig up from?");
 
        if (name_p)
-               *name_p = name;
+               *name_p = xstrdup(name);
        return found;
 }
 
@@ -1844,6 +1844,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
 
        if (orig)
                *orig = o;
+
+       free((char *)final_commit_name);
 }