git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Varun Naik <vcnaik94@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] read-cache.c: do not die if mmap fails
Date: Sun, 14 Jul 2019 11:59:54 -0700	[thread overview]
Message-ID: <xmqq7e8k5tn9.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20190714030153.22022-1-vcnaik94@gmail.com> (Varun Naik's message of "Sat, 13 Jul 2019 20:01:53 -0700")

Varun Naik <vcnaik94@gmail.com> writes:

> 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>
> ---
> I believe this is the only place that calls xmmap() when it should be
> calling xmmap_gently(). There is a related recent commit 3203566a71
> ("Use xmmap_gently instead of xmmap in use_pack", 2019-05-16).

Nice find and thanks for checking other callsites of xmmap().

>
>  read-cache.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index 22e7b9944e..4e30dafa9d 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -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);

      reply	other threads:[~2019-07-14 18:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-14  3:01 [PATCH] read-cache.c: do not die if mmap fails Varun Naik
2019-07-14 18:59 ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq7e8k5tn9.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=vcnaik94@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).