]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
[master] Update dmalloc to use a size_t as an argument
authorShawn Routhier <sar@isc.org>
Wed, 27 Jul 2016 17:41:26 +0000 (10:41 -0700)
committerShawn Routhier <sar@isc.org>
Wed, 27 Jul 2016 17:41:26 +0000 (10:41 -0700)
Update dmalloc to use a size_t as an argument which will
bring it in line with the call it makes to malloc and
avoid possible truncation.

RELNOTES
common/tests/test_alloc.c
includes/omapip/omapip.h
omapip/alloc.c

index 4d523494e30f0b73d84e815c5ae3de7d69677d05..c11458f4ad559f38c53863fdcc2387d2106e04b9 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -117,6 +117,10 @@ by Eric Young (eay@cryptsoft.com).
   verify the problem and fix.
   [ISC-Bugs #42849]
 
+- Change dmalloc to use a size_t as the length argument to bring it
+  in line with the call it will make to malloc().
+  [ISC-Bugs #40843]
+
                        Changes since 4.3.4b1
 
 - None
index a17a61e51f91ef53d593ef0c7003f14f5f4c3f06..07d6e6c047049d85bef3010a7d8647e3c73fc93e 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include <atf-c.h>
 #include "dhcpd.h"
+#include "omapip/alloc.h"
 
 static const char* checkString (struct data_string* ds, const char *src);
 
@@ -539,6 +540,85 @@ ATF_TC_BODY(data_string_terminate, tc) {
     data_string_forget(&new_string, MDL);
 }
 
+void checkBuffer(size_t test_size, const char *file, int line) {
+    char *buf;
+    size_t max_size;
+    /* Determine the maximum size we may have
+     * Depending on configuration options we may be adding some
+     * space to the allocated buffer for debugging purposes
+     * so remove that as well.
+     */
+    max_size = ((size_t)-1) - DMDSIZE;
+
+    if (test_size > max_size) {
+       atf_tc_skip("Test size greater than max size, %lx", test_size);
+       return;
+    }
+
+    /* We allocate the buffer and then try to set the last character
+     * to a known value.
+     */
+    buf = dmalloc(test_size, file, line);
+    if (buf != NULL) {
+       buf[test_size - 1] = 1;
+       if (buf[test_size - 1] != 1)
+           atf_tc_fail("Value mismatch for index %lu", test_size);
+       dfree(buf, file, line);
+    } else {
+       atf_tc_skip("Unable to allocate memory %lu", test_size);
+    }
+}
+
+ATF_TC(dmalloc_max32);
+
+ATF_TC_HEAD(dmalloc_max32, tc) {
+    atf_tc_set_md_var(tc, "descr", "dmalloc_max32 test, "
+                     "dmalloc 0xFFFFFFFF");
+}
+ATF_TC_BODY(dmalloc_max32, tc) {
+    checkBuffer(0XFFFFFFFF, MDL);
+}
+
+ATF_TC(dmalloc_med1);
+
+ATF_TC_HEAD(dmalloc_med1, tc) {
+    atf_tc_set_md_var(tc, "descr", "dmalloc_med1 test, "
+                     "dmalloc 0x80000000,");
+}
+ATF_TC_BODY(dmalloc_med1, tc) {
+    checkBuffer(0x80000000, MDL);
+}
+
+ATF_TC(dmalloc_med2);
+
+ATF_TC_HEAD(dmalloc_med2, tc) {
+    atf_tc_set_md_var(tc, "descr", "dmalloc_med2 test, "
+                     "dmalloc 0x7FFFFFFF, ");
+}
+ATF_TC_BODY(dmalloc_med2, tc) {
+    checkBuffer(0x7FFFFFFF,  MDL);
+}
+
+ATF_TC(dmalloc_med3);
+
+ATF_TC_HEAD(dmalloc_med3, tc) {
+    atf_tc_set_md_var(tc, "descr", "dmalloc_med3 test, "
+                     "dmalloc 0x10000000,");
+}
+ATF_TC_BODY(dmalloc_med3, tc) {
+    checkBuffer(0x10000000, MDL);
+}
+
+ATF_TC(dmalloc_small);
+
+ATF_TC_HEAD(dmalloc_small, tc) {
+    atf_tc_set_md_var(tc, "descr", "dmalloc_small test, "
+                     "dmalloc 0x0FFFFFFF");
+}
+ATF_TC_BODY(dmalloc_small, tc) {
+    checkBuffer(0X0FFFFFFF, MDL);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
     ATF_TP_ADD_TC(tp, buffer_allocate);
@@ -550,6 +630,11 @@ ATF_TP_ADD_TCS(tp)
     ATF_TP_ADD_TC(tp, data_string_copy_nobuf);
     ATF_TP_ADD_TC(tp, data_string_new);
     ATF_TP_ADD_TC(tp, data_string_terminate);
+    ATF_TP_ADD_TC(tp, dmalloc_max32);
+    ATF_TP_ADD_TC(tp, dmalloc_med1);
+    ATF_TP_ADD_TC(tp, dmalloc_med2);
+    ATF_TP_ADD_TC(tp, dmalloc_med3);
+    ATF_TP_ADD_TC(tp, dmalloc_small);
 
     return (atf_no_error());
 }
index afa9fd48744c692828d704ad8d6a1acbdd6cf90e..e7b472031a64ed4e573a9abaad1a56b17b9c2f29 100644 (file)
@@ -3,7 +3,7 @@
    Definitions for the object management API and protocol... */
 
 /*
- * Copyright (c) 2009,2013-2014 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2009,2013-2014,2016 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1996-2003 by Internet Software Consortium
  *
@@ -556,7 +556,7 @@ isc_result_t omapi_object_handle (omapi_handle_t *, omapi_object_t *);
 isc_result_t omapi_handle_lookup (omapi_object_t **, omapi_handle_t);
 isc_result_t omapi_handle_td_lookup (omapi_object_t **, omapi_typed_data_t *);
 
-void * dmalloc (unsigned, const char *, int);
+void * dmalloc (size_t, const char *, int);
 void dfree (void *, const char *, int);
 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
                defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
index a70fe21d4ecbbee5fc40222fc4cea66dcb3d526b..905434466cf26ffdd216991e044940ad0a5bc1a4 100644 (file)
@@ -4,7 +4,7 @@
    protocol... */
 
 /*
- * Copyright (c) 2012,2014 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2012,2014,2016 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 2009-2010 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1999-2003 by Internet Software Consortium
@@ -53,9 +53,9 @@ static void print_rc_hist_entry (int);
 #endif
 
 void *
-dmalloc(unsigned size, const char *file, int line) {
+dmalloc(size_t size, const char *file, int line) {
        unsigned char *foo;
-       unsigned len;
+       size_t len;
        void **bar;
 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
                defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)