From: Lennart Poettering Date: Fri, 24 Feb 2023 09:41:47 +0000 (+0100) Subject: mempool: fix tile alignment check X-Git-Tag: v254-rc1~1161 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9b47b18a1a53ad7d8d579bdcd6ca5af84c401f4a;p=thirdparty%2Fsystemd.git mempool: fix tile alignment check We should check alignment *after* determining the pointer points into our pool, not before. Otherwise might might end up checking alignment of the pointer relative to our base, even though it is taken relative to some other base. Follow-up for: a2b052b29f8bc141e94a4af95d1653a38a57eaeb See: https://github.com/systemd/systemd/pull/26393#issuecomment-1442295012 --- diff --git a/src/basic/mempool.c b/src/basic/mempool.c index fa319bffdbf..391f29b6678 100644 --- a/src/basic/mempool.c +++ b/src/basic/mempool.c @@ -98,9 +98,11 @@ static bool pool_contains(struct mempool *mp, struct pool *p, void *ptr) { return false; off = (uint8_t*) ptr - (uint8_t*) a; - assert(off % mp->tile_size == 0); + if (off >= mp->tile_size * p->n_tiles) + return false; - return off < mp->tile_size * p->n_tiles; + assert(off % mp->tile_size == 0); + return true; } static bool pool_is_unused(struct mempool *mp, struct pool *p) {