summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-01-12 08:59:40 +0000
committerPatrick Steinhardt <ps@pks.im>2018-01-26 13:08:40 +0000
commit275f103d4c515d40c73cc17ae7880f1091414393 (patch)
tree78fe556dfd33b9c49583cff1d0b0b4eebad25d10 /tests
parentc0487bde7e3891af7b759a092751294d703fef9d (diff)
downloadlibgit2-275f103d4c515d40c73cc17ae7880f1091414393.tar.gz
odb: reject reading and writing null OIDs
The null OID (hash with all zeroes) indicates a missing object in upstream git and is thus not a valid object ID. Add defensive measurements to avoid writing such a hash to the object database in the very unlikely case where some data results in the null OID. Furthermore, add shortcuts when reading the null OID from the ODB to avoid ever returning an object when a faulty repository may contain the null OID.
Diffstat (limited to 'tests')
-rw-r--r--tests/odb/backend/simple.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/odb/backend/simple.c b/tests/odb/backend/simple.c
index c0fcd403b..f4d29cc76 100644
--- a/tests/odb/backend/simple.c
+++ b/tests/odb/backend/simple.c
@@ -230,3 +230,21 @@ void test_odb_backend_simple__exists_with_highly_ambiguous_prefix(void)
cl_git_pass(git_odb_exists_prefix(&found, _odb, &_oid, 40));
cl_assert(git_oid_equal(&found, &_oid));
}
+
+void test_odb_backend_simple__null_oid_is_ignored(void)
+{
+ const fake_object objs[] = {
+ { "0000000000000000000000000000000000000000", "null oid content" },
+ { NULL, NULL }
+ };
+ git_oid null_oid = {{0}};
+ git_odb_object *obj;
+
+ setup_backend(objs);
+
+ cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0));
+ cl_assert(!git_odb_exists(_odb, &null_oid));
+
+ cl_git_fail_with(GIT_ENOTFOUND, git_odb_read(&obj, _odb, &null_oid));
+ cl_assert(giterr_last() && strstr(giterr_last()->message, "null OID"));
+}