diff options
author | Denis Lisov <dennis.lissov@gmail.com> | 2015-12-19 19:13:58 +0300 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2015-12-19 12:57:53 -0500 |
commit | 529a388ebb1b4e9d6ad8a1bb61dd8211833a5976 (patch) | |
tree | 775168217b7693e54ca4e79f47d2b54f9d8b0f98 | |
parent | bump to sandbox-2.11 (diff) | |
download | sandbox-529a388ebb1b4e9d6ad8a1bb61dd8211833a5976.tar.gz sandbox-529a388ebb1b4e9d6ad8a1bb61dd8211833a5976.tar.bz2 sandbox-529a388ebb1b4e9d6ad8a1bb61dd8211833a5976.zip |
libsandbox: fix old_malloc_size check on realloc
Realloc uses SB_MALLOC_TO_SIZE assuming it returns the usable size,
while it is really the mmap size, which is greater. Thus it may fail
to reallocate even if required.
URL: https://bugs.gentoo.org/568714
Signed-off-by: Denis Lisov <dennis.lissov@gmail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r-- | libsandbox/memory.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libsandbox/memory.c b/libsandbox/memory.c index 8581128..a2d69a2 100644 --- a/libsandbox/memory.c +++ b/libsandbox/memory.c @@ -40,7 +40,8 @@ static int sb_munmap(void *addr, size_t length) #define SB_MALLOC_TO_MMAP(ptr) ((void*)((uintptr_t)(ptr) - MIN_ALIGN)) #define SB_MMAP_TO_MALLOC(ptr) ((void*)((uintptr_t)(ptr) + MIN_ALIGN)) -#define SB_MALLOC_TO_SIZE(ptr) (*((size_t*)SB_MALLOC_TO_MMAP(ptr))) +#define SB_MALLOC_TO_MMAP_SIZE(ptr) (*((size_t*)SB_MALLOC_TO_MMAP(ptr))) +#define SB_MALLOC_TO_SIZE(ptr) (SB_MALLOC_TO_MMAP_SIZE(ptr) - MIN_ALIGN) void *malloc(size_t size) { @@ -57,7 +58,7 @@ void free(void *ptr) { if (ptr == NULL) return; - if (munmap(SB_MALLOC_TO_MMAP(ptr), SB_MALLOC_TO_SIZE(ptr))) + if (munmap(SB_MALLOC_TO_MMAP(ptr), SB_MALLOC_TO_MMAP_SIZE(ptr))) sb_ebort("sandbox memory corruption with free(%p): %s\n", ptr, strerror(errno)); } |