summaryrefslogtreecommitdiffhomepage
path: root/dbmalloc.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2020-10-15 19:55:15 +0800
committerMatt Johnston <matt@ucc.asn.au>2020-10-15 19:55:15 +0800
commit0e3e8db5bfca0c579be55e7580a46c593c1384be (patch)
tree2b1a718f633fb95c1f2d689a591cf9e8642697f3 /dbmalloc.c
parent78e17f6ee9a944430da3e517ee1fe384fd6b275b (diff)
parent17873e8c922eded2cec86184673a6d110df6403f (diff)
merge from main
--HG-- branch : fuzz
Diffstat (limited to 'dbmalloc.c')
-rw-r--r--dbmalloc.c84
1 files changed, 66 insertions, 18 deletions
diff --git a/dbmalloc.c b/dbmalloc.c
index e887d36..e2cdc8f 100644
--- a/dbmalloc.c
+++ b/dbmalloc.c
@@ -1,6 +1,64 @@
#include "dbmalloc.h"
#include "dbutil.h"
+
+void * m_calloc(size_t nmemb, size_t size) {
+ if (SIZE_T_MAX / nmemb < size) {
+ dropbear_exit("m_calloc failed");
+ }
+ return m_malloc(nmemb*size);
+}
+
+void * m_strdup(const char * str) {
+ char* ret;
+ unsigned int len;
+ len = strlen(str);
+
+ ret = m_malloc(len+1);
+ if (ret == NULL) {
+ dropbear_exit("m_strdup failed");
+ }
+ memcpy(ret, str, len+1);
+ return ret;
+}
+
+#if !DROPBEAR_TRACKING_MALLOC
+
+/* Simple wrappers around malloc etc */
+void * m_malloc(size_t size) {
+
+ void* ret;
+
+ if (size == 0) {
+ dropbear_exit("m_malloc failed");
+ }
+ ret = calloc(1, size);
+ if (ret == NULL) {
+ dropbear_exit("m_malloc failed");
+ }
+ return ret;
+
+}
+
+void * m_realloc(void* ptr, size_t size) {
+
+ void *ret;
+
+ if (size == 0) {
+ dropbear_exit("m_realloc failed");
+ }
+ ret = realloc(ptr, size);
+ if (ret == NULL) {
+ dropbear_exit("m_realloc failed");
+ }
+ return ret;
+}
+
+
+#else
+
+/* For fuzzing */
+
struct dbmalloc_header {
unsigned int epoch;
struct dbmalloc_header *prev;
@@ -90,13 +148,6 @@ void * m_malloc(size_t size) {
return &mem[sizeof(struct dbmalloc_header)];
}
-void * m_calloc(size_t nmemb, size_t size) {
- if (SIZE_T_MAX / nmemb < size) {
- dropbear_exit("m_calloc failed");
- }
- return m_malloc(nmemb*size);
-}
-
void * m_realloc(void* ptr, size_t size) {
char* mem = NULL;
struct dbmalloc_header* header = NULL;
@@ -128,17 +179,14 @@ void m_free_direct(void* ptr) {
free(header);
}
-void * m_strdup(const char * str) {
- char* ret;
- unsigned int len;
- len = strlen(str);
+#endif /* DROPBEAR_TRACKING_MALLOC */
- ret = m_malloc(len+1);
- if (ret == NULL) {
- dropbear_exit("m_strdup failed");
- }
- memcpy(ret, str, len+1);
- return ret;
+void * m_realloc_ltm(void* ptr, size_t oldsize, size_t newsize) {
+ (void)oldsize;
+ return m_realloc(ptr, newsize);
}
-
+void m_free_ltm(void *mem, size_t size) {
+ (void)size;
+ m_free_direct(mem);
+}