From: Johan Herland Date: Fri, 08 Jun 2007 00:08:14 GMT Subject: [PATCH] Fix failed tag parsing when tag object has no body/message (and thus ends with a single '\n') Message-ID: <200706080208.14571.johan@herland.net> In-Reply-To: <200706080147.50207.johan@herland.net> Thanks to Johannes Schindelin for discovering this. Also add a testcase for this condition. Signed-off-by: Johan Herland --- 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 .git/refs/tags/mytag 2>message' +############################################################ +# 24. create valid tag #4 (with empty message) + +cat >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