summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-05-16 11:51:50 +0900
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-05-16 11:51:50 +0900
commitf767178a5ada848867a7378053897bdfbac32590 (patch)
tree5a6a8f49b53dd52fc5e31bdb6a67105642399d93
parentMerge branch 'dt/raise-core-packed-git-limit' (diff)
parentcache-tree: reject entries with null sha1 (diff)
downloadtgif-f767178a5ada848867a7378053897bdfbac32590.tar.xz
Merge branch 'jk/no-null-sha1-in-cache-tree'
Code to update the cache-tree has been tightened so that we won't accidentally write out any 0{40} entry in the tree object. * jk/no-null-sha1-in-cache-tree: cache-tree: reject entries with null sha1
-rw-r--r--cache-tree.c4
-rw-r--r--read-cache.c5
-rwxr-xr-xt/t1601-index-bogus.sh22
-rwxr-xr-xt/t7009-filter-branch-null-sha1.sh6
4 files changed, 35 insertions, 2 deletions
diff --git a/cache-tree.c b/cache-tree.c
index 345ea35963..34baa6d85a 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -354,7 +354,9 @@ static int update_one(struct cache_tree *it,
entlen = pathlen - baselen;
i++;
}
- if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1)) {
+
+ if (is_null_sha1(sha1) ||
+ (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))) {
strbuf_release(&buffer);
if (expected_missing)
return -1;
diff --git a/read-cache.c b/read-cache.c
index 0d0081a11b..3339de8124 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2197,6 +2197,7 @@ static int do_write_index(struct index_state *istate, int newfd,
int entries = istate->cache_nr;
struct stat st;
struct strbuf previous_name_buf = STRBUF_INIT, *previous_name;
+ int drop_cache_tree = 0;
for (i = removed = extended = 0; i < entries; i++) {
if (cache[i]->ce_flags & CE_REMOVE)
@@ -2247,6 +2248,8 @@ static int do_write_index(struct index_state *istate, int newfd,
warning(msg, ce->name);
else
return error(msg, ce->name);
+
+ drop_cache_tree = 1;
}
if (ce_write_entry(&c, newfd, ce, previous_name) < 0)
return -1;
@@ -2265,7 +2268,7 @@ static int do_write_index(struct index_state *istate, int newfd,
if (err)
return -1;
}
- if (!strip_extensions && istate->cache_tree) {
+ if (!strip_extensions && !drop_cache_tree && istate->cache_tree) {
struct strbuf sb = STRBUF_INIT;
cache_tree_write(&sb, istate->cache_tree);
diff --git a/t/t1601-index-bogus.sh b/t/t1601-index-bogus.sh
new file mode 100755
index 0000000000..73cc9323cd
--- /dev/null
+++ b/t/t1601-index-bogus.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+test_description='test handling of bogus index entries'
+. ./test-lib.sh
+
+test_expect_success 'create tree with null sha1' '
+ tree=$(printf "160000 commit $_z40\\tbroken\\n" | git mktree)
+'
+
+test_expect_success 'read-tree refuses to read null sha1' '
+ test_must_fail git read-tree $tree
+'
+
+test_expect_success 'GIT_ALLOW_NULL_SHA1 overrides refusal' '
+ GIT_ALLOW_NULL_SHA1=1 git read-tree $tree
+'
+
+test_expect_success 'git write-tree refuses to write null sha1' '
+ test_must_fail git write-tree
+'
+
+test_done
diff --git a/t/t7009-filter-branch-null-sha1.sh b/t/t7009-filter-branch-null-sha1.sh
index c27f90f285..a8d9ec4987 100755
--- a/t/t7009-filter-branch-null-sha1.sh
+++ b/t/t7009-filter-branch-null-sha1.sh
@@ -31,6 +31,12 @@ test_expect_success 'setup: bring HEAD and index in sync' '
git commit -a -m "back to normal"
'
+test_expect_success 'noop filter-branch complains' '
+ test_must_fail git filter-branch \
+ --force --prune-empty \
+ --index-filter "true"
+'
+
test_expect_success 'filter commands are still checked' '
test_must_fail git filter-branch \
--force --prune-empty \