Merge branch 'js/fsck-tag-validation'
authorJunio C Hamano <gitster@pobox.com>
Mon, 22 Dec 2014 20:27:41 +0000 (12:27 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Dec 2014 20:27:41 +0000 (12:27 -0800)
New tag object format validation added in 2.2 showed garbage
after a tagname it reported in its error message.

* js/fsck-tag-validation:
index-pack: terminate object buffers with NUL
fsck: properly bound "invalid tag name" error message

builtin/index-pack.c
builtin/unpack-objects.c
fsck.c
t/t1450-fsck.sh
index a369f5535351645f15b08efb9d592be4257cdeff..46321176719808dd53a38675dd0d9c558ae336dd 100644 (file)
@@ -447,7 +447,7 @@ static void *unpack_entry_data(unsigned long offset, unsigned long size,
        if (type == OBJ_BLOB && size > big_file_threshold)
                buf = fixed_buf;
        else
-               buf = xmalloc(size);
+               buf = xmallocz(size);
 
        memset(&stream, 0, sizeof(stream));
        git_inflate_init(&stream);
@@ -552,7 +552,7 @@ static void *unpack_data(struct object_entry *obj,
        git_zstream stream;
        int status;
 
-       data = xmalloc(consume ? 64*1024 : obj->size);
+       data = xmallocz(consume ? 64*1024 : obj->size);
        inbuf = xmalloc((len < 64*1024) ? len : 64*1024);
 
        memset(&stream, 0, sizeof(stream));
index 855d94b90ba019ff19832ff49a76d6cc0077e956..ac6667242c562bb7a215982754211a3e035aae8a 100644 (file)
@@ -91,7 +91,7 @@ static void use(int bytes)
 static void *get_data(unsigned long size)
 {
        git_zstream stream;
-       void *buf = xmalloc(size);
+       void *buf = xmallocz(size);
 
        memset(&stream, 0, sizeof(stream));
 
diff --git a/fsck.c b/fsck.c
index 032419463126234fa855b934bae85fb27d6b26a4..10bcb651516e2c25979f8f5af62f87407289e8e6 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -426,7 +426,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 d00b70f99deffc6a4009fcea2ef387aade68d3e6..1f04b8aa3ff925f469ffa60ce47f9d5659b9acaa 100755 (executable)
@@ -229,8 +229,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 'tag with bad tagger' '