summaryrefslogtreecommitdiff
path: root/builtin/grep.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2020-10-11 16:03:28 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-10-12 19:25:14 (GMT)
commite30b1525fb017e86e08931a911f5451bf24176f5 (patch)
tree329664b34bbb539a400797e72d63a7308b5681b2 /builtin/grep.c
parentd4a392452e292ff924e79ec8458611c0f679d6d4 (diff)
downloadgit-e30b1525fb017e86e08931a911f5451bf24176f5.zip
git-e30b1525fb017e86e08931a911f5451bf24176f5.tar.gz
git-e30b1525fb017e86e08931a911f5451bf24176f5.tar.bz2
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>
Diffstat (limited to 'builtin/grep.c')
-rw-r--r--builtin/grep.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index c803738..e58e575 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);