am 198d13e8: Merge "make mmap fail on requests larger than PTRDIFF_MAX"

* commit '198d13e8c25e69f7dbda3f5e1a3258b13fe8db5d':
  make mmap fail on requests larger than PTRDIFF_MAX
This commit is contained in:
Josh Gao 2015-10-14 02:21:04 +00:00 committed by Android Git Automerger
commit 36ebee4f49
1 changed files with 8 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include <sys/mman.h>
#include <unistd.h>
#include "private/bionic_macros.h"
#include "private/ErrnoRestorer.h"
// mmap2(2) is like mmap(2), but the offset is in 4096-byte blocks, not bytes.
@ -45,6 +46,13 @@ void* mmap64(void* addr, size_t size, int prot, int flags, int fd, off64_t offse
return MAP_FAILED;
}
// prevent allocations large enough for `end - start` to overflow
size_t rounded = BIONIC_ALIGN(size, PAGE_SIZE);
if (rounded < size || size > PTRDIFF_MAX) {
errno = ENOMEM;
return MAP_FAILED;
}
bool is_private_anonymous = (flags & (MAP_PRIVATE | MAP_ANONYMOUS)) != 0;
void* result = __mmap2(addr, size, prot, flags, fd, offset >> MMAP2_SHIFT);