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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 11, 2020 at 18:03 UTC
e30b1525fb017e86e08931a911f5451bf24176f5
1 file changed
+11
builtin/grep.c
+11
@@ -670,6 +670,17 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
670
NULL, 0);
671
obj_read_unlock();
672
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
+
684
/* load the gitmodules file for this rev */
685
if (recurse_submodules) {
686
submodule_free(opt->repo);