From: Aki Tuomi Date: Tue, 1 Sep 2020 08:54:50 +0000 (+0300) Subject: lib: mempool-allocfree - Do not use PTR_OFFSET with negative offset X-Git-Tag: 2.3.13~88 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3aed1e852ac697a112bdc6ab8edb2d1f0ffb1095;p=thirdparty%2Fdovecot%2Fcore.git lib: mempool-allocfree - Do not use PTR_OFFSET with negative offset Avoids undefined behaviour sanitization error. --- diff --git a/src/lib/mempool-allocfree.c b/src/lib/mempool-allocfree.c index 239f984be1..07b74a89a0 100644 --- a/src/lib/mempool-allocfree.c +++ b/src/lib/mempool-allocfree.c @@ -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);