Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aad0bd6

Browse files
stspdotnamecarlosmn
authored andcommitted
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.
1 parent ea8dedc commit aad0bd6

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/unix/map.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int git__page_size(size_t *page_size)
2626

2727
int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
2828
{
29-
int mprot = 0;
29+
int mprot = PROT_READ;
3030
int mflag = 0;
3131

3232
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
3535
out->len = 0;
3636

3737
if (prot & GIT_PROT_WRITE)
38-
mprot = PROT_WRITE;
39-
else if (prot & GIT_PROT_READ)
40-
mprot = PROT_READ;
38+
mprot |= PROT_WRITE;
4139

4240
if ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)
4341
mflag = MAP_SHARED;

0 commit comments

Comments
 (0)