{"thread":{"id":"22009","subject":"[PATCH] Prevent git blame from segfaulting on a missing author name","startedAt":"2009-12-22T18:51:41Z","lastAt":"2009-12-22T18:51:41Z","messageCount":1,"participants":["David Reiss"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"130253","messageId":"4B31153D.4@facebook.com","threadId":"22009","inReplyTo":null,"subject":"[PATCH] Prevent git blame from segfaulting on a missing author name","fromName":"David Reiss","fromEmail":"dreiss@facebook.com","sentAt":"2009-12-22T18:51:41Z","receivedAt":"2009-12-22T18:51:41Z","isPatch":true,"sender":{"key":"dreiss@facebook.com","avatar":null},"body":"The author name should never be missing in a valid commit, but\ngit shouldn't segfault no matter what is in the object database.\n(Most of the C code was written by Junio.)\n\nSigned-off-by: David Reiss <dreiss@facebook.com>\n---\n builtin-blame.c  |   13 ++++++++++---\n t/t8003-blame.sh |   13 +++++++++++++\n 2 files changed, 23 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex d4e25a5..14830a3 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -1305,6 +1305,7 @@ static void get_ac_line(const char *inbuf, const char *what,\n \terror_out:\n \t\t/* Ugh */\n \t\t*tz = \"(unknown)\";\n+\t\tstrcpy(person, *tz);\n \t\tstrcpy(mail, *tz);\n \t\t*time = 0;\n \t\treturn;\n@@ -1314,20 +1315,26 @@ static void get_ac_line(const char *inbuf, const char *what,\n \ttmp = person;\n \ttmp += len;\n \t*tmp = 0;\n-\twhile (*tmp != ' ')\n+\twhile (person < tmp && *tmp != ' ')\n \t\ttmp--;\n+\tif (tmp == person)\n+\t\tgoto error_out;\n \t*tz = tmp+1;\n \ttzlen = (person+len)-(tmp+1);\n \n \t*tmp = 0;\n-\twhile (*tmp != ' ')\n+\twhile (person < tmp && *tmp != ' ')\n \t\ttmp--;\n+\tif (tmp == person)\n+\t\tgoto error_out;\n \t*time = strtoul(tmp, NULL, 10);\n \ttimepos = tmp;\n \n \t*tmp = 0;\n-\twhile (*tmp != ' ')\n+\twhile (person < tmp && *tmp != ' ')\n \t\ttmp--;\n+\tif (tmp <= person)\n+\t\treturn;\n \tmailpos = tmp + 1;\n \t*tmp = 0;\n \tmaillen = timepos - tmp;\ndiff --git a/t/t8003-blame.sh b/t/t8003-blame.sh\nindex 13c25f1..ad834f2 100755\n--- a/t/t8003-blame.sh\n+++ b/t/t8003-blame.sh\n@@ -144,4 +144,17 @@ test_expect_success 'blame path that used to be a directory' '\n \tgit blame HEAD^.. -- path\n '\n \n+test_expect_success 'blame to a commit with no author name' '\n+  TREE=`git rev-parse HEAD:`\n+  cat >badcommit <<EOF\n+tree $TREE\n+author <noname> 1234567890 +0000\n+committer David Reiss <dreiss@facebook.com> 1234567890 +0000\n+\n+some message\n+EOF\n+  COMMIT=`git hash-object -t commit -w badcommit`\n+  git --no-pager blame $COMMIT -- uno >/dev/null\n+'\n+\n test_done\n-- \n1.6.3.3\n"}]}