grep: handle corrupt index files early
authorStefan Beller <sbeller@google.com>
Tue, 15 May 2018 01:04:25 +0000 (18:04 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 May 2018 00:48:32 +0000 (09:48 +0900)
Any other caller of 'repo_read_index' dies upon a negative return of
it, so grep should, too.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c
index 5a6cfe6b45b06b6b75ea399a83cb8dcf7e197141..567565b2d2dc5cf9a4d5c971588e6c2c398883a9 100644 (file)
@@ -480,7 +480,8 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
                strbuf_addstr(&name, repo->submodule_prefix);
        }
 
-       repo_read_index(repo);
+       if (repo_read_index(repo) < 0)
+               die("index file corrupt");
 
        for (nr = 0; nr < repo->index->cache_nr; nr++) {
                const struct cache_entry *ce = repo->index->cache[nr];