read-cache.c: do not die if mmap fails
authorVarun Naik <vcnaik94@gmail.com>
Sun, 14 Jul 2019 03:01:53 +0000 (20:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 14 Jul 2019 22:22:29 +0000 (15:22 -0700)
do_read_index() mmaps the index, or tries to die with an error message
on failure. It should call xmmap_gently(), which returns MAP_FAILED,
rather than xmmap(), which dies with its own error message.

An easy way to cause this mmap to fail is by setting $GIT_INDEX_FILE to
a path to a directory and then invoking any command that reads from the
index.

Signed-off-by: Varun Naik <vcnaik94@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache.c
index 22e7b9944e35d257b144fe06dce2073c91d4819f..4e30dafa9dfa26a027a665e7e1509f6437ec79de 100644 (file)
@@ -2140,7 +2140,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
        if (mmap_size < sizeof(struct cache_header) + the_hash_algo->rawsz)
                die(_("%s: index file smaller than expected"), path);
 
-       mmap = xmmap(NULL, mmap_size, PROT_READ, MAP_PRIVATE, fd, 0);
+       mmap = xmmap_gently(NULL, mmap_size, PROT_READ, MAP_PRIVATE, fd, 0);
        if (mmap == MAP_FAILED)
                die_errno(_("%s: unable to map index file"), path);
        close(fd);