From 83dabbd8faa477a7246a220c9a96ff0bf24404db Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Fri, 24 Aug 2018 03:52:01 -0400 Subject: [PATCH] fix handling of random bases for class regions --- malloc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/malloc.c b/malloc.c index 8b36146..ca6ed68 100644 --- a/malloc.c +++ b/malloc.c @@ -364,7 +364,7 @@ static void *slab_allocate(size_t requested_size) { static size_t slab_size_class(void *p) { size_t offset = (char *)p - (char *)ro.slab_region_start; - return offset / class_region_size; + return offset / real_class_region_size; } static size_t slab_usable_size(void *p) { @@ -597,8 +597,9 @@ COLD static void init_slow_path(void) { fatal_error("mutex initialization failed"); } - size_t gap = (get_random_size_uniform(&rng, (real_class_region_size - class_region_size) / PAGE_SIZE) + 1) * PAGE_SIZE; - c->class_region_start = (char *)ro.slab_region_start + class_region_size * i + gap; + size_t bound = (real_class_region_size - class_region_size) / PAGE_SIZE - 1; + size_t gap = (get_random_size_uniform(&rng, bound) + 1) * PAGE_SIZE; + c->class_region_start = (char *)ro.slab_region_start + real_class_region_size * i + gap; size_t size = size_classes[i]; if (size == 0) {