Commit 9a53df7e0ac364ccba5bd11e9d6c62091f564397

Vicent Marti 2011-03-29T19:40:02

refs: Don't allow references to inexistent OIDs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
diff --git a/src/refs.c b/src/refs.c
index c6508ca..8170695 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1319,6 +1319,13 @@ int git_reference_set_oid(git_reference *ref, const git_oid *id)
 
 	ref_oid = (reference_oid *)ref;
 
+	assert(ref->owner);
+
+	/* Don't let the user create references to OIDs that
+	 * don't exist in the ODB */
+	if (!git_odb_exists(git_repository_database(ref->owner), id))
+		return GIT_ENOTFOUND;
+
 	/* duplicate the reference;
 	 * this copy will stay on the packfile cache */
 	if (ref->type & GIT_REF_PACKED) {