]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pool: fix memory leak
authorVictor Julien <victor@inliniac.net>
Fri, 12 Feb 2016 09:48:26 +0000 (10:48 +0100)
committerVictor Julien <victor@inliniac.net>
Sat, 13 Feb 2016 08:45:49 +0000 (09:45 +0100)
Due to pointer size mishandling, the pool code could consider a
block of memory inside the 'preallocated' block. It would then not
free the block.

configure.ac
src/suricata-common.h
src/util-pool.c

index 6daa5e6df8bd9000919b1fdb47bfdee4d6f0ca18..79578fb31058a46caa89fc9195de8b41a03df1b2 100644 (file)
     # Checks for libraries.
 
     # Checks for header files.
+    AC_CHECK_HEADERS([stddef.h])
     AC_CHECK_HEADERS([arpa/inet.h assert.h ctype.h errno.h fcntl.h inttypes.h])
     AC_CHECK_HEADERS([getopt.h])
     AC_CHECK_HEADERS([limits.h netdb.h netinet/in.h poll.h sched.h signal.h])
index 388f1a429cd3ff90bdaed3f35edb55a8e0bbb609..4d60f787818391780ee6053a533a229c51cace5a 100644 (file)
 #include <stdio.h>
 #endif
 
+#if HAVE_STDDEF_H
+#include <stddef.h>
+#endif
+
 #if HAVE_STDINT_h
 #include <stdint.h>
 #endif
index 6f405252046d235190793ce68c0b6699ef6b6b4b..4d4d5e40ea21d4f7f40ba95cdb9f93d2bd89a3bf 100644 (file)
@@ -54,10 +54,10 @@ static int PoolMemset(void *pitem, void *initdata)
 
 /**
  * \brief Check if data is preallocated
- * \retval 0 or -1 if not inside */
+ * \retval 0 if not inside the prealloc'd block, 1 if inside */
 static int PoolDataPreAllocated(Pool *p, void *data)
 {
-    int delta = data - p->data_buffer;
+    ptrdiff_t delta = data - p->data_buffer;
     if ((delta < 0) || (delta > p->data_buffer_size)) {
         return 0;
     }