git rev-list: fix invalid typecast
git rev-list passes rev_list_info, not rev_list objects. Without this fix, rev-list enables or disables the --verify-objects option depending on a read from an undefined memory location. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Clemens Buchacher committed
Feb 13, 2012 at 21:17 UTC
cb8da70547af5cd5c8e03be5a236971951e81277
2 files changed
+28
-2
builtin/rev-list.c
+2
-2
@@ -180,10 +180,10 @@ static void show_object(struct object *obj,
180
const struct name_path *path, const char *component,
181
void *cb_data)
182
{
183
- struct rev_info *info = cb_data;
183
+ struct rev_list_info *info = cb_data;
184
185
finish_object(obj, path, component, cb_data);
186
- if (info->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
186
+ if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
187
parse_object(obj->sha1);
188
show_object_with_name(stdout, obj, path, component);
189
}
t/t1450-fsck.sh
+26
@@ -191,4 +191,30 @@ test_expect_success 'cleaned up' '
191
test_cmp empty actual
192
'
193
194
+test_expect_success 'rev-list --verify-objects' '
195
+ git rev-list --verify-objects --all >/dev/null 2>out &&
196
+ test_cmp empty out
197
+'
198
+
199
+test_expect_success 'rev-list --verify-objects with bad sha1' '
200
+ sha=$(echo blob | git hash-object -w --stdin) &&
201
+ old=$(echo $sha | sed "s+^..+&/+") &&
202
+ new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff &&
203
+ sha="$(dirname $new)$(basename $new)" &&
204
+ mv .git/objects/$old .git/objects/$new &&
205
+ test_when_finished "remove_object $sha" &&
206
+ git update-index --add --cacheinfo 100644 $sha foo &&
207
+ test_when_finished "git read-tree -u --reset HEAD" &&
208
+ tree=$(git write-tree) &&
209
+ test_when_finished "remove_object $tree" &&
210
+ cmt=$(echo bogus | git commit-tree $tree) &&
211
+ test_when_finished "remove_object $cmt" &&
212
+ git update-ref refs/heads/bogus $cmt &&
213
+ test_when_finished "git update-ref -d refs/heads/bogus" &&
214
+
215
+ test_might_fail git rev-list --verify-objects refs/heads/bogus >/dev/null 2>out &&
216
+ cat out &&
217
+ grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out
218
+'
219
+
220
test_done