@matheusbsbs / matheus-bagliano / commits / e64c1b0053
Fork 0

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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 18, 2009 at 13:58 UTC e64c1b0053f2dc4fc5b434a9806b90318bac9592
1 file changed +5 -2
builtin-for-each-ref.c
+5 -2
@@ -339,8 +339,11 @@ static const char *copy_name(const char *buf)
339 static const char *copy_email(const char *buf)
340 {
341 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)
347 return "";
348 return xmemdupz(email, eoemail + 1 - email);
349 }