{"thread":{"id":"46453","subject":"[PATCH] blame: fix memory corruption scrambling revision name in error message","startedAt":"2017-07-24T17:08:44Z","lastAt":"2017-07-24T17:08:44Z","messageCount":1,"participants":["SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"324956","messageId":"20170724170620.19745-1-szeder.dev@gmail.com","threadId":"46453","inReplyTo":null,"subject":"[PATCH] blame: fix memory corruption scrambling revision name in error message","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-07-24T17:06:20Z","receivedAt":"2017-07-24T17:08:44Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"When attempting to blame a non-existing path, git should show an error\nmessage like this:\n\n  $ git blame e83c51633 -- nonexisting-file\n  fatal: no such path nonexisting-file in e83c51633\n\nSince the recent commit 835c49f7d (blame: rework methods that\ndetermine 'final' commit, 2017-05-24) the revision name is either\nmissing or some scrambled characters are shown instead.  The reason is\nthat the revision name must be duplicated, because it is invalidated\nwhen the pending objects array is cleared in the meantime, but this\ncommit dropped the duplication.\n\nRestore the duplication of the revision name in the affected functions\n(find_single_final() and find_single_initial()).\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n blame.c | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/blame.c b/blame.c\nindex 91e26e93e..9ee0a375f 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -1662,8 +1662,8 @@ static struct commit *find_single_final(struct rev_info *revs,\n \t\tfound = (struct commit *)obj;\n \t\tname = revs->pending.objects[i].name;\n \t}\n-\tif (name_p)\n-\t\t*name_p = name;\n+\tif (name_p && name)\n+\t\t*name_p = xstrdup(name);\n \treturn found;\n }\n \n@@ -1735,7 +1735,7 @@ static struct commit *find_single_initial(struct rev_info *revs,\n \t\tdie(\"No commit to dig up from?\");\n \n \tif (name_p)\n-\t\t*name_p = name;\n+\t\t*name_p = xstrdup(name);\n \treturn found;\n }\n \n@@ -1843,6 +1843,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam\n \n \tif (orig)\n \t\t*orig = o;\n+\n+\tfree((char *)final_commit_name);\n }\n \n \n-- \n2.14.0.rc0.88.ge338f4246\n\n"}]}