Skip to content

Commit e64c1b0

Browse files
peffgitster
authored andcommitted
for-each-ref: fix segfault in copy_email
You can trigger a segfault in git.git by doing: git for-each-ref --format='%(taggeremail)' refs/tags/v0.99 The v0.99 tag is special in that it contains no "tagger" header. The bug is obvious in copy_email, which carefully checks to make sure the result of a strchr is non-NULL, but only after already having used it to perform other work. The fix is to move the check up. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5acb3e5 commit e64c1b0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

builtin-for-each-ref.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,11 @@ static const char *copy_name(const char *buf)
339339
static const char *copy_email(const char *buf)
340340
{
341341
const char *email = strchr(buf, '<');
342-
const char *eoemail = strchr(email, '>');
343-
if (!email || !eoemail)
342+
const char *eoemail;
343+
if (!email)
344+
return "";
345+
eoemail = strchr(email, '>');
346+
if (!eoemail)
344347
return "";
345348
return xmemdupz(email, eoemail + 1 - email);
346349
}

0 commit comments

Comments
 (0)