fsck: handle NULL return of lookup_blob() and lookup_tree()
lookup_blob() and lookup_tree() can return NULL if they find an object of an unexpected type. Accessing the object member is undefined in that case. Cast the result to a struct object pointer instead; we can do that because object is the first member of all object types. This trick is already used in other places in the code. An error message is already shown by object_as_type(), which is called by the lookup functions. The walk callback functions are expected to handle NULL object pointers passed to them, but put_object_name() needs a valid object, so avoid calling it without one. Suggested-by: SZEDER Gábor <szeder.dev@gmail.com> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
4010f1d1b7
commit
2720f6db5d
8
fsck.c
8
fsck.c
@ -358,15 +358,15 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
|
||||
continue;
|
||||
|
||||
if (S_ISDIR(entry.mode)) {
|
||||
obj = &lookup_tree(entry.oid)->object;
|
||||
if (name)
|
||||
obj = (struct object *)lookup_tree(entry.oid);
|
||||
if (name && obj)
|
||||
put_object_name(options, obj, "%s%s/", name,
|
||||
entry.path);
|
||||
result = options->walk(obj, OBJ_TREE, data, options);
|
||||
}
|
||||
else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
|
||||
obj = &lookup_blob(entry.oid)->object;
|
||||
if (name)
|
||||
obj = (struct object *)lookup_blob(entry.oid);
|
||||
if (name && obj)
|
||||
put_object_name(options, obj, "%s%s", name,
|
||||
entry.path);
|
||||
result = options->walk(obj, OBJ_BLOB, data, options);
|
||||
|
Reference in New Issue
Block a user