Skip to content

Commit cb8da70

Browse files
Clemens Buchachergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0482e8 commit cb8da70

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

builtin/rev-list.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ static void show_object(struct object *obj,
180180
const struct name_path *path, const char *component,
181181
void *cb_data)
182182
{
183-
struct rev_info *info = cb_data;
183+
struct rev_list_info *info = cb_data;
184184

185185
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)
187187
parse_object(obj->sha1);
188188
show_object_with_name(stdout, obj, path, component);
189189
}

t/t1450-fsck.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,30 @@ test_expect_success 'cleaned up' '
191191
test_cmp empty actual
192192
'
193193

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+
194220
test_done

0 commit comments

Comments
 (0)