Skip to content

Commit 6b60354

Browse files
committed
vm-mempool: widen heap size multiply to size_t
The obj_size (uint16_t) * capacity (uint32_t) product was evaluated in 32-bit and only then widened to the size_t that the allocator takes, so a product over 4 GB would wrap before the widening. Current callers derive capacity from fixed pool-size config (~10 MB max), so this is not triggerable today, but cast one operand to size_t to do the multiply in 64-bit as defensive hardening against future pool-size increases.
1 parent e29f53b commit 6b60354

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

core/vm-mempool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ vm_mempool_create(vm_mempool_t *pool, uint16_t obj_size,
125125
memset(pool->alloc_bitmap, 0, bitmap_size);
126126
memset(pool->ref_bitmap, 0, bitmap_size);
127127

128-
pool->heap = VM_MEMPOOL_ALLOC(obj_size * capacity);
128+
pool->heap = VM_MEMPOOL_ALLOC((size_t)obj_size * capacity);
129129
if(pool->heap == 0) {
130130
VM_MEMPOOL_FREE(pool->alloc_bitmap);
131131
VM_MEMPOOL_FREE(pool->ref_bitmap);
132132
VM_DEBUG(VM_DEBUG_MEDIUM,
133133
"Failed to create a mempool heap of size %lu\n",
134-
(unsigned long)(obj_size * capacity));
134+
(unsigned long)((size_t)obj_size * capacity));
135135
return 0;
136136
}
137137

0 commit comments

Comments
 (0)