Commit aad0bd6bc78b79bb8c0778c0c135c167d359fe12

Stefan Sperling 2014-11-03T13:46:56

Fix segmentation fault observed on OpenBSD/sparc64 A non-readable mapping of a file causes an access violation in the pack tests. Always use PROT_READ to work around this.

diff --git a/src/unix/map.c b/src/unix/map.c
index 0a235d5..87ee659 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -26,7 +26,7 @@ int git__page_size(size_t *page_size)
 
 int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
 {
-	int mprot = 0;
+	int mprot = PROT_READ;
 	int mflag = 0;
 
 	GIT_MMAP_VALIDATE(out, len, prot, flags);
@@ -35,9 +35,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
 	out->len = 0;
 
 	if (prot & GIT_PROT_WRITE)
-		mprot = PROT_WRITE;
-	else if (prot & GIT_PROT_READ)
-		mprot = PROT_READ;
+		mprot |= PROT_WRITE;
 
 	if ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)
 		mflag = MAP_SHARED;