]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsck: properly bound "invalid tag name" error message
authorJeff King <peff@peff.net>
Mon, 8 Dec 2014 05:48:13 +0000 (00:48 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Dec 2014 19:54:25 +0000 (11:54 -0800)
When we detect an invalid tag-name header in a tag object,
like, "tag foo bar\n", we feed the pointer starting at "foo
bar" to a printf "%s" formatter. This shows the name, as we
want, but then it keeps printing the rest of the tag buffer,
rather than stopping at the end of the line.

Our tests did not notice because they look only for the
matching line, but the bug is that we print much more than
we wanted to. So we also adjust the test to be more exact.

Note that when fscking tags with "index-pack --strict", this
is even worse. index-pack does not add a trailing
NUL-terminator after the object, so we may actually read
past the buffer and print uninitialized memory. Running
t5302 with valgrind does notice the bug for that reason.

Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fsck.c
t/t1450-fsck.sh

diff --git a/fsck.c b/fsck.c
index 2fffa434a5763abb6d7895ee8c7582307766ee62..88c92e82d19c9848b560822fe7c8002e759cf655 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -423,7 +423,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
        }
        strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
        if (check_refname_format(sb.buf, 0))
-               error_func(&tag->object, FSCK_WARN, "invalid 'tag' name: %s", buffer);
+               error_func(&tag->object, FSCK_WARN, "invalid 'tag' name: %.*s",
+                          (int)(eol - buffer), buffer);
        buffer = eol + 1;
 
        if (!skip_prefix(buffer, "tagger ", &buffer))
index 1b96b4045bd270c5f3af2dd10d126d7b4b4ce706..7850607783cf6d59b893b93a641e4c00d96c56db 100755 (executable)
@@ -209,8 +209,12 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
        echo $tag >.git/refs/tags/wrong &&
        test_when_finished "git update-ref -d refs/tags/wrong" &&
        git fsck --tags 2>out &&
-       grep "invalid .tag. name" out &&
-       grep "expected .tagger. line" out
+
+       cat >expect <<-EOF &&
+       warning in tag $tag: invalid '\''tag'\'' name: wrong name format
+       warning in tag $tag: invalid format - expected '\''tagger'\'' line
+       EOF
+       test_cmp expect out
 '
 
 test_expect_success 'cleaned up' '