Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sandbox:master commit in: libsandbox/
Date: Sat, 19 Dec 2015 18:10:18
Message-Id: 1450547873.529a388ebb1b4e9d6ad8a1bb61dd8211833a5976.vapier@gentoo
1 commit: 529a388ebb1b4e9d6ad8a1bb61dd8211833a5976
2 Author: Denis Lisov <dennis.lissov <AT> gmail <DOT> com>
3 AuthorDate: Sat Dec 19 16:13:58 2015 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Sat Dec 19 17:57:53 2015 +0000
6 URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=529a388e
7
8 libsandbox: fix old_malloc_size check on realloc
9
10 Realloc uses SB_MALLOC_TO_SIZE assuming it returns the usable size,
11 while it is really the mmap size, which is greater. Thus it may fail
12 to reallocate even if required.
13
14 URL: https://bugs.gentoo.org/568714
15 Signed-off-by: Denis Lisov <dennis.lissov <AT> gmail.com>
16 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>
17
18 libsandbox/memory.c | 5 +++--
19 1 file changed, 3 insertions(+), 2 deletions(-)
20
21 diff --git a/libsandbox/memory.c b/libsandbox/memory.c
22 index 8581128..a2d69a2 100644
23 --- a/libsandbox/memory.c
24 +++ b/libsandbox/memory.c
25 @@ -40,7 +40,8 @@ static int sb_munmap(void *addr, size_t length)
26
27 #define SB_MALLOC_TO_MMAP(ptr) ((void*)((uintptr_t)(ptr) - MIN_ALIGN))
28 #define SB_MMAP_TO_MALLOC(ptr) ((void*)((uintptr_t)(ptr) + MIN_ALIGN))
29 -#define SB_MALLOC_TO_SIZE(ptr) (*((size_t*)SB_MALLOC_TO_MMAP(ptr)))
30 +#define SB_MALLOC_TO_MMAP_SIZE(ptr) (*((size_t*)SB_MALLOC_TO_MMAP(ptr)))
31 +#define SB_MALLOC_TO_SIZE(ptr) (SB_MALLOC_TO_MMAP_SIZE(ptr) - MIN_ALIGN)
32
33 void *malloc(size_t size)
34 {
35 @@ -57,7 +58,7 @@ void free(void *ptr)
36 {
37 if (ptr == NULL)
38 return;
39 - if (munmap(SB_MALLOC_TO_MMAP(ptr), SB_MALLOC_TO_SIZE(ptr)))
40 + if (munmap(SB_MALLOC_TO_MMAP(ptr), SB_MALLOC_TO_MMAP_SIZE(ptr)))
41 sb_ebort("sandbox memory corruption with free(%p): %s\n",
42 ptr, strerror(errno));
43 }