@matheusbsbs / matheus-bagliano / commits / 5d44cd1c8b
Fork 0

Fix git-fsck-objects SIGSEGV/divide-by-zero

If you try to fsck a repository that isn't entirely empty, but that has no inter-object references (ie all the objects are blobs, and don't refer to anything else), git-fsck-objects currently fails. This probably cannot happen in practice, but can be tested with something like git init-db touch dummy git add dummy git fsck-objects where the fsck will die by a divide-by-zero when it tries to look up the references from the one object it found (hash_obj() will do a modulus by refs_hash_size). On some other archiectures (ppc, sparc) the divide-by-zero will go unnoticed, and we'll instead SIGSEGV when we hit the "refs_hash[j]" access. So move the test that should protect against this from mark_reachable() into lookup_object_refs(), which incidentally in the process also fixes mark_reachable() itself (it used to not mark the one object that _was_ reachable, because it decided that it had no refs too early). Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Sep 4, 2006 at 08:34 UTC 5d44cd1c8b27fb677fedc886303d38b19fbb07f7
1 file changed +5 -4
object-refs.c
+5 -4
@@ -55,9 +55,13 @@ static void add_object_refs(struct object *obj, struct object_refs *ref)
55
56 struct object_refs *lookup_object_refs(struct object *obj)
57 {
58 - int j = hash_obj(obj, refs_hash_size);
58 struct object_refs *ref;
59 + int j;
60
61 + /* nothing to lookup */
62 + if (!refs_hash_size)
63 + return NULL;
64 + j = hash_obj(obj, refs_hash_size);
65 while ((ref = refs_hash[j]) != NULL) {
66 if (ref->base == obj)
67 break;
@@ -125,9 +129,6 @@ void mark_reachable(struct object *obj, unsigned int mask)
129
130 if (!track_object_refs)
131 die("cannot do reachability with object refs turned off");
128 - /* nothing to lookup */
129 - if (!refs_hash_size)
130 - return;
132 /* If we've been here already, don't bother */
133 if (obj->flags & mask)
134 return;