Skip to content

Commit c8cba79

Browse files
David Reissgitster
authored andcommitted
Prevent git blame from segfaulting on a missing author name
The human-readable author and committer name can be missing from commits imported from foreign SCM interfaces. Make sure we parse the "author" and "committer" line a bit more leniently and avoid segfaulting by assuming the name always exists. Signed-off-by: David Reiss <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e49ca97 commit c8cba79

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

builtin-blame.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,7 @@ static void get_ac_line(const char *inbuf, const char *what,
13051305
error_out:
13061306
/* Ugh */
13071307
*tz = "(unknown)";
1308+
strcpy(person, *tz);
13081309
strcpy(mail, *tz);
13091310
*time = 0;
13101311
return;
@@ -1314,20 +1315,26 @@ static void get_ac_line(const char *inbuf, const char *what,
13141315
tmp = person;
13151316
tmp += len;
13161317
*tmp = 0;
1317-
while (*tmp != ' ')
1318+
while (person < tmp && *tmp != ' ')
13181319
tmp--;
1320+
if (tmp <= person)
1321+
goto error_out;
13191322
*tz = tmp+1;
13201323
tzlen = (person+len)-(tmp+1);
13211324

13221325
*tmp = 0;
1323-
while (*tmp != ' ')
1326+
while (person < tmp && *tmp != ' ')
13241327
tmp--;
1328+
if (tmp <= person)
1329+
goto error_out;
13251330
*time = strtoul(tmp, NULL, 10);
13261331
timepos = tmp;
13271332

13281333
*tmp = 0;
1329-
while (*tmp != ' ')
1334+
while (person < tmp && *tmp != ' ')
13301335
tmp--;
1336+
if (tmp <= person)
1337+
return;
13311338
mailpos = tmp + 1;
13321339
*tmp = 0;
13331340
maillen = timepos - tmp;

t/t8003-blame.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,17 @@ test_expect_success 'blame path that used to be a directory' '
144144
git blame HEAD^.. -- path
145145
'
146146

147+
test_expect_success 'blame to a commit with no author name' '
148+
TREE=`git rev-parse HEAD:`
149+
cat >badcommit <<EOF
150+
tree $TREE
151+
author <noname> 1234567890 +0000
152+
committer David Reiss <[email protected]> 1234567890 +0000
153+
154+
some message
155+
EOF
156+
COMMIT=`git hash-object -t commit -w badcommit`
157+
git --no-pager blame $COMMIT -- uno >/dev/null
158+
'
159+
147160
test_done

0 commit comments

Comments
 (0)