aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-08-29 17:03:16 +0000
committerBart Polot <bart@net.in.tum.de>2012-08-29 17:03:16 +0000
commit308eab2402422262d9b895f98008a4d5b176be59 (patch)
treef68a6d824cc7b23ce9df45a3fc14732a0625752b
parent3f8a19f31a2458b639f12a0f31eb182d5c524c18 (diff)
downloadgnunet-308eab2402422262d9b895f98008a4d5b176be59.tar.gz
gnunet-308eab2402422262d9b895f98008a4d5b176be59.zip
- Fix memory posioning on OS X (MSIZE is pre-defined to 256, doesnt HAVE_MALLOC_USABLE_MEMORY -> compile error)
-rw-r--r--configure.ac4
-rw-r--r--src/util/common_allocation.c13
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
444AC_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])) 444AC_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]))
445 445
446# Checks for headers that are only required on some systems or opional (and where we do NOT abort if they are not there) 446# Checks for headers that are only required on some systems or opional (and where we do NOT abort if they are not there)
447AC_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]) 447AC_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])
448 448
449SAVE_LDFLAGS=$LDFLAGS 449SAVE_LDFLAGS=$LDFLAGS
450SAVE_CPPFLAGS=$CPPFLAGS 450SAVE_CPPFLAGS=$CPPFLAGS
@@ -717,7 +717,7 @@ AC_FUNC_VPRINTF
717AC_HEADER_SYS_WAIT 717AC_HEADER_SYS_WAIT
718AC_TYPE_OFF_T 718AC_TYPE_OFF_T
719AC_TYPE_UID_T 719AC_TYPE_UID_T
720AC_CHECK_FUNCS([atoll stat64 strnlen mremap setrlimit sysconf initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid $funcstocheck getifaddrs freeifaddrs getresgid mallinfo malloc_usable_size]) 720AC_CHECK_FUNCS([atoll stat64 strnlen mremap setrlimit sysconf initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid $funcstocheck getifaddrs freeifaddrs getresgid mallinfo malloc_size malloc_usable_size])
721 721
722# restore LIBS 722# restore LIBS
723LIBS=$SAVE_LIBS 723LIBS=$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 @@
28#if HAVE_MALLOC_H 28#if HAVE_MALLOC_H
29#include <malloc.h> 29#include <malloc.h>
30#endif 30#endif
31#if HAVE_MALLOC_MALLOC_H
32#include <malloc/malloc.h>
33#endif
31 34
32#define LOG(kind,...) GNUNET_log_from (kind, "util",__VA_ARGS__) 35#define LOG(kind,...) GNUNET_log_from (kind, "util",__VA_ARGS__)
33 36
@@ -192,10 +195,12 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
192#endif 195#endif
193 196
194#if WINDOWS 197#if WINDOWS
195#define MSIZE(p) _msize (p) 198#define M_SIZE(p) _msize (p)
196#endif 199#endif
197#if HAVE_MALLOC_USABLE_SIZE 200#if HAVE_MALLOC_USABLE_SIZE
198#define MSIZE(p) malloc_usable_size (p) 201#define M_SIZE(p) malloc_usable_size (p)
202#elif HAVE_MALLOC_SIZE
203#define M_SIZE(p) malloc_size (p)
199#endif 204#endif
200 205
201/** 206/**
@@ -214,12 +219,12 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
214 ptr = &((size_t *) ptr)[-1]; 219 ptr = &((size_t *) ptr)[-1];
215 mem_used -= *((size_t *) ptr); 220 mem_used -= *((size_t *) ptr);
216#endif 221#endif
217#if defined(MSIZE) 222#if defined(M_SIZE)
218#if ENABLE_POISONING 223#if ENABLE_POISONING
219 { 224 {
220 size_t i; 225 size_t i;
221 char baadfood[5] = BAADFOOD_STR; 226 char baadfood[5] = BAADFOOD_STR;
222 size_t s = MSIZE (ptr); 227 size_t s = M_SIZE (ptr);
223 for (i = 0; i < s; i++) 228 for (i = 0; i < s; i++)
224 ((char *) ptr)[i] = baadfood[i % 4]; 229 ((char *) ptr)[i] = baadfood[i % 4];
225 } 230 }