1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-29 21:55:36 +03:00

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: a2b052b29f
See: https://github.com/systemd/systemd/pull/26393#issuecomment-1442295012
This commit is contained in:
Lennart Poettering 2023-02-24 10:41:47 +01:00
parent ccacde77f3
commit 9b47b18a1a

View File

@ -98,9 +98,11 @@ static bool pool_contains(struct mempool *mp, struct pool *p, void *ptr) {
return false; return false;
off = (uint8_t*) ptr - (uint8_t*) a; 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) { static bool pool_is_unused(struct mempool *mp, struct pool *p) {