]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: mempool-allocfree - Do not use PTR_OFFSET with negative offset
authorAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 1 Sep 2020 08:54:50 +0000 (11:54 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 22 Oct 2020 12:16:16 +0000 (12:16 +0000)
Avoids undefined behaviour sanitization error.

src/lib/mempool-allocfree.c

index 239f984be14dbdfab14cce858eb85b9b5b8e0300..07b74a89a0b14c2bd1db451da376e718d6911c36 100644 (file)
@@ -234,7 +234,9 @@ static void *pool_block_attach(struct allocfree_pool *apool, struct pool_block *
 static struct pool_block *
 pool_block_detach(struct allocfree_pool *apool, unsigned char *mem)
 {
-       struct pool_block *block = PTR_OFFSET(mem, -SIZEOF_POOLBLOCK);
+       /* cannot use PTR_OFFSET because of negative value */
+       i_assert((uintptr_t)mem >= SIZEOF_POOLBLOCK);
+       struct pool_block *block = (struct pool_block *)(mem - SIZEOF_POOLBLOCK);
 
        /* make sure the block we are dealing with is correct */
        i_assert(block->block == mem);