From: René Scharfe Date: Sun, 11 Oct 2020 16:03:28 +0000 (+0200) Subject: grep: handle deref_tag() returning NULL X-Git-Tag: v2.30.0-rc0~156^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e30b1525fb017e86e08931a911f5451bf24176f5;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/grep.c b/builtin/grep.c index c8037388c6..e58e57504c 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -670,6 +670,17 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec, NULL, 0); obj_read_unlock(); + if (!real_obj) { + char hex[GIT_MAX_HEXSZ + 1]; + const char *name = list->objects[i].name; + + if (!name) { + oid_to_hex_r(hex, &list->objects[i].item->oid); + name = hex; + } + die(_("invalid object '%s' given."), name); + } + /* load the gitmodules file for this rev */ if (recurse_submodules) { submodule_free(opt->repo);