Skip to content

Commit e30b152

Browse files
rscharfegitster
authored andcommitted
grep: handle deref_tag() returning NULL
deref_tag() can return NULL. Exit gracefully in that case instead of blindly dereferencing the return value. .name shouldn't ever be NULL, but grep_object() handles that case explicitly, so let's be defensive here as well and show the broken object's ID if it happens to lack a name after all. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d4a3924 commit e30b152

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

builtin/grep.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,17 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
670670
NULL, 0);
671671
obj_read_unlock();
672672

673+
if (!real_obj) {
674+
char hex[GIT_MAX_HEXSZ + 1];
675+
const char *name = list->objects[i].name;
676+
677+
if (!name) {
678+
oid_to_hex_r(hex, &list->objects[i].item->oid);
679+
name = hex;
680+
}
681+
die(_("invalid object '%s' given."), name);
682+
}
683+
673684
/* load the gitmodules file for this rev */
674685
if (recurse_submodules) {
675686
submodule_free(opt->repo);

0 commit comments

Comments
 (0)