Skip to content

Commit

Permalink
for-each-ref: fix segfault in copy_email
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
peff authored and gitster committed May 20, 2009
1 parent 5acb3e5 commit e64c1b0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions builtin-for-each-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,11 @@ static const char *copy_name(const char *buf)
static const char *copy_email(const char *buf)
{
const char *email = strchr(buf, '<');
const char *eoemail = strchr(email, '>');
if (!email || !eoemail)
const char *eoemail;
if (!email)
return "";
eoemail = strchr(email, '>');
if (!eoemail)
return "";
return xmemdupz(email, eoemail + 1 - email);
}
Expand Down

0 comments on commit e64c1b0

Please sign in to comment.