From 95b4ff3931064ff222e87eecf6af504ba55069d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 21 Aug 2021 14:52:40 +0200 Subject: compat: let git_mmap use malloc(3) directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit xmalloc() dies on error, allows zero-sized allocations and enforces GIT_ALLOC_LIMIT for testing. Our mmap replacement doesn't need any of that. Let's cut out the wrapper, reject zero-sized requests as required by POSIX and use malloc(3) directly. Allocation errors were needlessly handled by git_mmap() before; this code becomes reachable now. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- compat/mmap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'compat') diff --git a/compat/mmap.c b/compat/mmap.c index 14d31010df..8d6c02d4bc 100644 --- a/compat/mmap.c +++ b/compat/mmap.c @@ -7,7 +7,12 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of if (start != NULL || flags != MAP_PRIVATE || prot != PROT_READ) die("Invalid usage of mmap when built with NO_MMAP"); - start = xmalloc(length); + if (length == 0) { + errno = EINVAL; + return MAP_FAILED; + } + + start = malloc(length); if (start == NULL) { errno = ENOMEM; return MAP_FAILED; -- cgit v1.2.3