Skip to content

Commit 1cb4b3d

Browse files
committed
Merge branch 'js/fsck-tag-validation'
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
2 parents 14d4aab + a1e920a commit 1cb4b3d

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

builtin/index-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static void *unpack_entry_data(unsigned long offset, unsigned long size,
447447
if (type == OBJ_BLOB && size > big_file_threshold)
448448
buf = fixed_buf;
449449
else
450-
buf = xmalloc(size);
450+
buf = xmallocz(size);
451451

452452
memset(&stream, 0, sizeof(stream));
453453
git_inflate_init(&stream);
@@ -552,7 +552,7 @@ static void *unpack_data(struct object_entry *obj,
552552
git_zstream stream;
553553
int status;
554554

555-
data = xmalloc(consume ? 64*1024 : obj->size);
555+
data = xmallocz(consume ? 64*1024 : obj->size);
556556
inbuf = xmalloc((len < 64*1024) ? len : 64*1024);
557557

558558
memset(&stream, 0, sizeof(stream));

builtin/unpack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void use(int bytes)
9191
static void *get_data(unsigned long size)
9292
{
9393
git_zstream stream;
94-
void *buf = xmalloc(size);
94+
void *buf = xmallocz(size);
9595

9696
memset(&stream, 0, sizeof(stream));
9797

fsck.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
426426
}
427427
strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
428428
if (check_refname_format(sb.buf, 0))
429-
error_func(&tag->object, FSCK_WARN, "invalid 'tag' name: %s", buffer);
429+
error_func(&tag->object, FSCK_WARN, "invalid 'tag' name: %.*s",
430+
(int)(eol - buffer), buffer);
430431
buffer = eol + 1;
431432

432433
if (!skip_prefix(buffer, "tagger ", &buffer))

t/t1450-fsck.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,12 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
229229
echo $tag >.git/refs/tags/wrong &&
230230
test_when_finished "git update-ref -d refs/tags/wrong" &&
231231
git fsck --tags 2>out &&
232-
grep "invalid .tag. name" out &&
233-
grep "expected .tagger. line" out
232+
233+
cat >expect <<-EOF &&
234+
warning in tag $tag: invalid '\''tag'\'' name: wrong name format
235+
warning in tag $tag: invalid format - expected '\''tagger'\'' line
236+
EOF
237+
test_cmp expect out
234238
'
235239

236240
test_expect_success 'tag with bad tagger' '

0 commit comments

Comments
 (0)