dovecot-1.0: If giving pool_alloconly_create() less than 40 byte...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jan 3 21:20:42 EET 2008


details:   http://hg.dovecot.org/dovecot-1.0/rev/c7456f4b0430
changeset: 5507:c7456f4b0430
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jan 03 21:20:38 2008 +0200
description:
If giving pool_alloconly_create() less than 40 bytes as the initial size
with 32bit systems, destroying the pool crashed.

diffstat:

1 file changed, 7 insertions(+), 4 deletions(-)
src/lib/mempool-alloconly.c |   11 +++++++----

diffs (28 lines):

diff -r fb14b51b33f5 -r c7456f4b0430 src/lib/mempool-alloconly.c
--- a/src/lib/mempool-alloconly.c	Wed Jan 02 23:45:40 2008 +0200
+++ b/src/lib/mempool-alloconly.c	Thu Jan 03 21:20:38 2008 +0200
@@ -94,10 +94,11 @@ pool_t pool_alloconly_create(const char 
 pool_t pool_alloconly_create(const char *name __attr_unused__, size_t size)
 {
 	struct alloconly_pool apool, *new_apool;
-	size_t min_alloc = sizeof(struct alloconly_pool) + SIZEOF_POOLBLOCK;
-
-#ifdef DEBUG
-	min_alloc += strlen(name) + 1;
+	size_t min_alloc = MEM_ALIGN(sizeof(struct alloconly_pool)) +
+		SIZEOF_POOLBLOCK;
+
+#ifdef DEBUG
+	min_alloc += MEM_ALIGN(strlen(name) + 1);
 #endif
 
 	/* create a fake alloconly_pool so we can call block_alloc() */
@@ -112,6 +113,8 @@ pool_t pool_alloconly_create(const char 
 	/* now allocate the actual alloconly_pool from the created block */
 	new_apool = p_new(&apool.pool, struct alloconly_pool, 1);
 	*new_apool = apool;
+	/* the pool allocation must be from the first block */
+	i_assert(apool.block->prev == NULL);
 #ifdef DEBUG
 	if (strncmp(name, MEMPOOL_GROWING, strlen(MEMPOOL_GROWING)) == 0) {
 		name += strlen(MEMPOOL_GROWING);


More information about the dovecot-cvs mailing list