[PATCH] Fix failed tag parsing when tag object has no body/message (and thus ends with a single '\n')
From: Johan Herland <hidden>
Date: 2016-06-15 22:43:14
Subsystem:
the rest · Maintainer:
Linus Torvalds
Thanks to Johannes Schindelin [off-list ref] for discovering this. Also add a testcase for this condition. Signed-off-by: Johan Herland <redacted> --- This patch should hopefully fix your problem. ...Johan t/t3800-mktag.sh | 15 +++++++++++++++ tag.c | 9 ++------- 2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh
index ac9008a..ac7cbbc 100755
--- a/t/t3800-mktag.sh
+++ b/t/t3800-mktag.sh@@ -399,5 +399,20 @@ test_expect_success \ 'create valid tag #4' \ 'git-mktag <tag.sig >.git/refs/tags/mytag 2>message' +############################################################ +# 24. create valid tag #4 (with empty message) + +cat >tag.sig <<EOF +object $head +type commit +tag mytag +keywords note +tagger a +EOF + +test_expect_success \ + 'create valid tag #4' \ + 'git-mktag <tag.sig >.git/refs/tags/mytag 2>message' + test_done
diff --git a/tag.c b/tag.c
index e371179..875145b 100644
--- a/tag.c
+++ b/tag.c@@ -131,10 +131,6 @@ int parse_and_verify_tag_buffer(struct tag *item, const char *data, const unsign header_end = memchr(tagger_line, '\n', end - tagger_line); if (!header_end++) return error("char" PD_FMT ": could not find \"\\n\" after \"tagger\"", tagger_line - data); - if (end - header_end < 1) - return error("char" PD_FMT ": premature end of data", header_end - data); - if (*header_end != '\n') /* header must end with "\n\n" */ - return error("char" PD_FMT ": could not find blank line after header section", header_end - data); } else { /* Treat tagger line as optional */
@@ -148,9 +144,8 @@ int parse_and_verify_tag_buffer(struct tag *item, const char *data, const unsign header_end = tagger_line; } - if (end - header_end < 1) - return error("char" PD_FMT ": premature end of data", header_end - data); - if (*header_end != '\n') /* header must end with "\n\n" */ + /* header must end with "\n\n", but "\n" is acceptable if at EOF */ + if (header_end < end - 1 && *header_end != '\n') /* not at EOF, and next char is not '\n' */ return error("char" PD_FMT ": could not find blank line after header section", header_end - data); /*
--
1.5.2