read-cache.c: do not die if mmap fails

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>

Varun Naik committed Jul 13, 2019 at 20:01 UTC 02638d1e1153eb89d51a72de51ad854a88c9a178
1 file changed +1 -1
read-cache.c
+1 -1
@@ -2140,7 +2140,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
2140 if (mmap_size < sizeof(struct cache_header) + the_hash_algo->rawsz)
2141 die(_("%s: index file smaller than expected"), path);
2142
2143 - mmap = xmmap(NULL, mmap_size, PROT_READ, MAP_PRIVATE, fd, 0);
2143 + mmap = xmmap_gently(NULL, mmap_size, PROT_READ, MAP_PRIVATE, fd, 0);
2144 if (mmap == MAP_FAILED)
2145 die_errno(_("%s: unable to map index file"), path);
2146 close(fd);