ref-filter: initialize empty name or email fields

Formatting $(taggername) on headerless tags such as v0.99 in Git causes a SIGABRT with error "munmap_chunk(): invalid pointer", because of an oversight in commit f0062d3b74 (ref-filter: free item->value and item->value->s, 2018-10-19). Signed-off-by: Mischa POSLAWSKY <git@shiar.nl> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mischa POSLAWSKY committed Aug 17, 2019 at 23:51 UTC 8b3f33ef11821a6a030f789eeb0b3af01469901e
2 files changed +22 -3
ref-filter.c
+3 -3
@@ -976,7 +976,7 @@ static const char *copy_name(const char *buf)
976 if (!strncmp(cp, " <", 2))
977 return xmemdupz(buf, cp - buf);
978 }
979 - return "";
979 + return xstrdup("");
980 }
981
982 static const char *copy_email(const char *buf)
@@ -984,10 +984,10 @@ static const char *copy_email(const char *buf)
984 const char *email = strchr(buf, '<');
985 const char *eoemail;
986 if (!email)
987 - return "";
987 + return xstrdup("");
988 eoemail = strchr(email, '>');
989 if (!eoemail)
990 - return "";
990 + return xstrdup("");
991 return xmemdupz(email, eoemail + 1 - email);
992 }
993
t/t6300-for-each-ref.sh
+19
@@ -485,6 +485,25 @@ test_expect_success 'Check ambiguous head and tag refs II (loose)' '
485 test_cmp expected actual
486 '
487
488 +test_expect_success 'create tag without tagger' '
489 + git tag -a -m "Broken tag" taggerless &&
490 + git tag -f taggerless $(git cat-file tag taggerless |
491 + sed -e "/^tagger /d" |
492 + git hash-object --stdin -w -t tag)
493 +'
494 +
495 +test_atom refs/tags/taggerless type 'commit'
496 +test_atom refs/tags/taggerless tag 'taggerless'
497 +test_atom refs/tags/taggerless tagger ''
498 +test_atom refs/tags/taggerless taggername ''
499 +test_atom refs/tags/taggerless taggeremail ''
500 +test_atom refs/tags/taggerless taggerdate ''
501 +test_atom refs/tags/taggerless committer ''
502 +test_atom refs/tags/taggerless committername ''
503 +test_atom refs/tags/taggerless committeremail ''
504 +test_atom refs/tags/taggerless committerdate ''
505 +test_atom refs/tags/taggerless subject 'Broken tag'
506 +
507 test_expect_success 'an unusual tag with an incomplete line' '
508
509 git tag -m "bogo" bogo &&