debugged and fixed libdislocator malfunction on MacOSX
MODIFY
libdislocator/libdislocator.so.c
libdislocator/libdislocator.so.c
@@ -88,7 +88,7 @@ static u8 alloc_verbose, /* Additional debug messages */
hard_fail, /* abort() when max_mem exceeded? */
no_calloc_over; /* abort() on calloc() overflows? */
-#ifdef __OpenBSD__
+#if defined __OpenBSD__ || defined __APPLE__
#define __thread
#warning no thread support available
#endif
@@ -121,7 +121,7 @@ static void* __dislocator_alloc(size_t len) {
ret = mmap(NULL, (1 + PG_COUNT(len + 8)) * PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
- if (ret == (void*)-1) {
+ if (ret == MAP_FAILED) {
if (hard_fail) FATAL("mmap() failed on alloc (OOM?)");

MODIFY
test/test.sh
test/test.sh
@@ -281,8 +281,8 @@ test -e ../libtokencap.so && {
test -e ../libdislocator.so && {
{
ulimit -c 1
- # DYLD_INSERT_LIBRARIES is used on Darwin/MacOSX
- LD_PRELOAD=../libdislocator.so DYLD_INSERT_LIBRARIES=../libdislocator.so ./test-compcov BUFFEROVERFLOW > test.out 2> /dev/null
+ # DYLD_INSERT_LIBRARIES and DYLD_FORCE_FLAT_NAMESPACE is used on Darwin/MacOSX
+ LD_PRELOAD=../libdislocator.so DYLD_INSERT_LIBRARIES=../libdislocator.so DYLD_FORCE_FLAT_NAMESPACE=1 ./test-compcov BUFFEROVERFLOW > test.out 2> /dev/null
} > /dev/null 2>&1
grep -q BUFFEROVERFLOW test.out > /dev/null 2>&1 && {
$ECHO "$RED[!] libdislocator did not detect the memory corruption"

debugged and fixed libdislocator malfunction on MacOSX