From 308eab2402422262d9b895f98008a4d5b176be59 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 29 Aug 2012 17:03:16 +0000 Subject: [PATCH] - Fix memory posioning on OS X (MSIZE is pre-defined to 256, doesnt HAVE_MALLOC_USABLE_MEMORY -> compile error) --- configure.ac | 4 ++-- src/util/common_allocation.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index be8209869..553b6a33c 100644 --- a/configure.ac +++ b/configure.ac @@ -444,7 +444,7 @@ AC_HEADER_STDC AC_CHECK_HEADERS([fcntl.h math.h errno.h ctype.h limits.h stdio.h stdlib.h string.h unistd.h stdarg.h signal.h locale.h sys/stat.h sys/types.h],,AC_MSG_ERROR([Compiling GNUnet requires standard UNIX headers files])) # Checks for headers that are only required on some systems or opional (and where we do NOT abort if they are not there) -AC_CHECK_HEADERS([malloc.h langinfo.h sys/param.h sys/mount.h sys/statvfs.h sys/select.h sockLib.h sys/mman.h sys/msg.h sys/vfs.h arpa/inet.h fcntl.h libintl.h netdb.h netinet/in.h netinet/in_systm.h sys/ioctl.h sys/socket.h sys/time.h unistd.h kstat.h sys/sysinfo.h kvm.h sys/file.h sys/resource.h ifaddrs.h mach/mach.h stddef.h sys/timeb.h terminos.h argz.h ucred.h endian.h sys/endian.h execinfo.h]) +AC_CHECK_HEADERS([malloc.h malloc/malloc.h langinfo.h sys/param.h sys/mount.h sys/statvfs.h sys/select.h sockLib.h sys/mman.h sys/msg.h sys/vfs.h arpa/inet.h fcntl.h libintl.h netdb.h netinet/in.h netinet/in_systm.h sys/ioctl.h sys/socket.h sys/time.h unistd.h kstat.h sys/sysinfo.h kvm.h sys/file.h sys/resource.h ifaddrs.h mach/mach.h stddef.h sys/timeb.h terminos.h argz.h ucred.h endian.h sys/endian.h execinfo.h]) SAVE_LDFLAGS=$LDFLAGS SAVE_CPPFLAGS=$CPPFLAGS @@ -717,7 +717,7 @@ AC_FUNC_VPRINTF AC_HEADER_SYS_WAIT AC_TYPE_OFF_T AC_TYPE_UID_T -AC_CHECK_FUNCS([atoll stat64 strnlen mremap setrlimit sysconf initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid $funcstocheck getifaddrs freeifaddrs getresgid mallinfo malloc_usable_size]) +AC_CHECK_FUNCS([atoll stat64 strnlen mremap setrlimit sysconf initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid $funcstocheck getifaddrs freeifaddrs getresgid mallinfo malloc_size malloc_usable_size]) # restore LIBS LIBS=$SAVE_LIBS diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 90af6e091..ab8715a6d 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c @@ -28,6 +28,9 @@ #if HAVE_MALLOC_H #include #endif +#if HAVE_MALLOC_MALLOC_H +#include +#endif #define LOG(kind,...) GNUNET_log_from (kind, "util",__VA_ARGS__) @@ -192,10 +195,12 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) #endif #if WINDOWS -#define MSIZE(p) _msize (p) +#define M_SIZE(p) _msize (p) #endif #if HAVE_MALLOC_USABLE_SIZE -#define MSIZE(p) malloc_usable_size (p) +#define M_SIZE(p) malloc_usable_size (p) +#elif HAVE_MALLOC_SIZE +#define M_SIZE(p) malloc_size (p) #endif /** @@ -214,12 +219,12 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber) ptr = &((size_t *) ptr)[-1]; mem_used -= *((size_t *) ptr); #endif -#if defined(MSIZE) +#if defined(M_SIZE) #if ENABLE_POISONING { size_t i; char baadfood[5] = BAADFOOD_STR; - size_t s = MSIZE (ptr); + size_t s = M_SIZE (ptr); for (i = 0; i < s; i++) ((char *) ptr)[i] = baadfood[i % 4]; } -- 2.25.1