# [PATCH] compat: make sure git_mmap is not expected to write

4 messages from 2018-10-23 to 2018-10-24. Participants: carlo, Johannes Schindelin, Carlo Marcelo Arenas Belón, Junio C Hamano.
Thread: https://gitlist.dev/t/49644

## carlo, 2018-10-23 05:12

Subject: [PATCH] compat: make sure git_mmap is not expected to write
Message-ID: <20181023051216.64266-1-carenas@gmail.com>
URL: https://gitlist.dev/e/20181023051216.64266-1-carenas%40gmail.com

```
in f48000fc ("Yank writing-back support from gitfakemmap.", 2005-10-08)
support for writting back changes was removed but the specific prot
flag that would be used was not checked for)

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 compat/mmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compat/mmap.c b/compat/mmap.c
index 7f662fef7b..14d31010df 100644
--- a/compat/mmap.c
+++ b/compat/mmap.c
@@ -4,7 +4,7 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
 {
 	size_t n = 0;
 
-	if (start != NULL || !(flags & MAP_PRIVATE))
+	if (start != NULL || flags != MAP_PRIVATE || prot != PROT_READ)
 		die("Invalid usage of mmap when built with NO_MMAP");
 
 	start = xmalloc(length);
-- 
2.19.1


```

## Johannes Schindelin, 2018-10-23 10:13

Subject: Re: [PATCH] compat: make sure git_mmap is not expected to write
Message-ID: <nycvar.QRO.7.76.6.1810231212190.4546@tvgsbejvaqbjf.bet>
URL: https://gitlist.dev/e/nycvar.QRO.7.76.6.1810231212190.4546%40tvgsbejvaqbjf.bet
In-Reply-To: <20181023051216.64266-1-carenas@gmail.com>

```
Hi carlo,

your mail's "From:" line does not record your full name, but the
Signed-off-by: line does. Let's use the latter?

On Mon, 22 Oct 2018, carlo wrote:

> in f48000fc ("Yank writing-back support from gitfakemmap.", 2005-10-08)
> support for writting back changes was removed but the specific prot
> flag that would be used was not checked for)
> 
> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>

ACK!

Thank you,
Johannes

> ---
>  compat/mmap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/compat/mmap.c b/compat/mmap.c
> index 7f662fef7b..14d31010df 100644
> --- a/compat/mmap.c
> +++ b/compat/mmap.c
> @@ -4,7 +4,7 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
>  {
>  	size_t n = 0;
>  
> -	if (start != NULL || !(flags & MAP_PRIVATE))
> +	if (start != NULL || flags != MAP_PRIVATE || prot != PROT_READ)
>  		die("Invalid usage of mmap when built with NO_MMAP");
>  
>  	start = xmalloc(length);
> -- 
> 2.19.1
> 
> 
```

## Carlo Marcelo Arenas Belón, 2018-10-23 12:35

Subject: [PATCH v2] compat: make sure git_mmap is not expected to write
Message-ID: <20181023123519.91317-1-carenas@gmail.com>
URL: https://gitlist.dev/e/20181023123519.91317-1-carenas%40gmail.com
In-Reply-To: <nycvar.QRO.7.76.6.1810231212190.4546@tvgsbejvaqbjf.bet>

```
in f48000fc ("Yank writing-back support from gitfakemmap.", 2005-10-08)
support for writting back changes was removed but the specific prot
flag that would be used was not checked for

Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
Changes in v2:
    
* reset-author to match signature
* cleanup commit message and add ACK

 compat/mmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compat/mmap.c b/compat/mmap.c
index 7f662fef7b..14d31010df 100644
--- a/compat/mmap.c
+++ b/compat/mmap.c
@@ -4,7 +4,7 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
 {
 	size_t n = 0;
 
-	if (start != NULL || !(flags & MAP_PRIVATE))
+	if (start != NULL || flags != MAP_PRIVATE || prot != PROT_READ)
 		die("Invalid usage of mmap when built with NO_MMAP");
 
 	start = xmalloc(length);
-- 
2.19.1


```

## Junio C Hamano, 2018-10-24 01:43

Subject: Re: [PATCH v2] compat: make sure git_mmap is not expected to write
Message-ID: <xmqqr2ggqftu.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqr2ggqftu.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <20181023123519.91317-1-carenas@gmail.com>

```
Carlo Marcelo Arenas Belón  <carenas@gmail.com> writes:

> in f48000fc ("Yank writing-back support from gitfakemmap.", 2005-10-08)
> support for writting back changes was removed but the specific prot
> flag that would be used was not checked for
>
> Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
> ---
> Changes in v2:
>     
> * reset-author to match signature
> * cleanup commit message and add ACK

Thanks.  Looking good.


>  compat/mmap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/compat/mmap.c b/compat/mmap.c
> index 7f662fef7b..14d31010df 100644
> --- a/compat/mmap.c
> +++ b/compat/mmap.c
> @@ -4,7 +4,7 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
>  {
>  	size_t n = 0;
>  
> -	if (start != NULL || !(flags & MAP_PRIVATE))
> +	if (start != NULL || flags != MAP_PRIVATE || prot != PROT_READ)
>  		die("Invalid usage of mmap when built with NO_MMAP");
>  
>  	start = xmalloc(length);

```
