]> git.ipfire.org Git - thirdparty/git.git/commitdiff
grep: handle deref_tag() returning NULL
authorRené Scharfe <l.s.r@web.de>
Sun, 11 Oct 2020 16:03:28 +0000 (18:03 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Oct 2020 19:25:14 +0000 (12:25 -0700)
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>
builtin/grep.c

index c8037388c6e7fd4c62d1a019b1c7b17f020370df..e58e57504c3b5108eb09c9d8198efaa4128ff363 100644 (file)
@@ -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);