summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@HansenPartnership.com>2020-04-18 10:39:49 -0700
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2020-04-18 10:39:49 -0700
commit75ffb00dc876c63a32bf5f20605908fd5476a81c (patch)
treef21f58af7452e4a555248697d7738c38418b8d2c
parent58711cd753b0c3189b905a50272fd37c779d8860 (diff)
downloadsecret-memory-preloader-75ffb00dc876c63a32bf5f20605908fd5476a81c.tar.gz
Add a load more assertion checks
-rw-r--r--preload.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/preload.c b/preload.c
index 19bdd70..0e0c253 100644
--- a/preload.c
+++ b/preload.c
@@ -242,6 +242,7 @@ static struct malloc_chunk *find_free(size_t size)
struct malloc_chunk *c, *found = NULL;
for (c = m.free.fd; c != &m.free; c = c->fd) {
+ ASSERT(prev_in_use(c));
if (chunk_size(c) < size)
continue;
if (found && chunk_size(found) < chunk_size(c))
@@ -261,8 +262,12 @@ static void split_free_chunk(struct malloc_chunk *c, size_t size)
unlink_free_chunk(c);
c->head |= CINUSE_BIT;
new_c = next_chunk(c);
- if (new_c)
+ if (new_c) {
+ ASSERT(!prev_in_use(new_c));
+ ASSERT(new_c->prev_foot == chunk_size(c));
+
new_c->head |= PINUSE_BIT;
+ }
return;
}
@@ -279,8 +284,11 @@ static void split_free_chunk(struct malloc_chunk *c, size_t size)
c->fd->bk = new_c;
/* and adjust the next prev_foot if there is one */
n = next_chunk(new_c);
- if (n)
+ if (n) {
+ ASSERT(!prev_in_use(n));
+ ASSERT(n->prev_foot == csize);
n->prev_foot = chunk_size(new_c);
+ }
}
static void *dlmalloc(size_t size)
@@ -319,6 +327,7 @@ void CRYPTO_free(void *ptr, const char *file, int line)
return;
c = mem2chunk(ptr);
+ ASSERT(in_use(c));
/* shred the data */
memset(ptr, 0, chunk_size(c) - CHUNK_SIZE);