Skip to content

Commit 02638d1

Browse files
varuncnaikgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b697d92 commit 02638d1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

read-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
21402140
if (mmap_size < sizeof(struct cache_header) + the_hash_algo->rawsz)
21412141
die(_("%s: index file smaller than expected"), path);
21422142

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);
21442144
if (mmap == MAP_FAILED)
21452145
die_errno(_("%s: unable to map index file"), path);
21462146
close(fd);

0 commit comments

Comments
 (0)