From bfa0e1110a4685aaf4f2778d584d7fca4ccd0fa3 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Fri, 20 Jun 2025 06:34:51 -0400 Subject: [PATCH 1/2] mem: Don't print `Buddy_Allocator.tail` This is always a pointer past the end of the buffer given to `buddy_allocator_init`, which could be an invalid address. Printing may result in a segmentation violation. --- core/mem/allocators.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/mem/allocators.odin b/core/mem/allocators.odin index a5a7d9951..335cf008e 100644 --- a/core/mem/allocators.odin +++ b/core/mem/allocators.odin @@ -2196,7 +2196,7 @@ The buddy allocator data. */ Buddy_Allocator :: struct { head: ^Buddy_Block, - tail: ^Buddy_Block, + tail: ^Buddy_Block `fmt:"-"`, alignment: uint, } From 4d4356e80607273c91f107c91c89c78feef22c73 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Fri, 20 Jun 2025 06:44:44 -0400 Subject: [PATCH 2/2] mem: Guard against `Buddy_Allocator` overwriting metadata --- core/mem/allocators.odin | 1 + 1 file changed, 1 insertion(+) diff --git a/core/mem/allocators.odin b/core/mem/allocators.odin index 335cf008e..0eacb1b65 100644 --- a/core/mem/allocators.odin +++ b/core/mem/allocators.odin @@ -2328,6 +2328,7 @@ buddy_allocator_alloc_bytes_non_zeroed :: proc(b: ^Buddy_Allocator, size: uint) } found.is_free = false data := ([^]byte)(found)[b.alignment:][:size] + assert(cast(uintptr)raw_data(data)+cast(uintptr)size < cast(uintptr)buddy_block_next(found), "Buddy_Allocator has made an allocation which overlaps a block header.") // ensure_poisoned(data) // sanitizer.address_unpoison(data) return data, nil