From c13a97e82a111b89cde0ce025315b3d83efb8fe3 Mon Sep 17 00:00:00 2001 From: Winford Date: Sun, 9 Feb 2025 08:12:39 +0000 Subject: [PATCH] Fix comparison between unsigned subtraction and the value 0 Fixes a false positive critical security bug revealed by codeql in code-scanning/30. Since it is established before this check that the size does not excede the the free_space, the check is changed to make sure `free_space - size` does not result in 0 free_space, else `should_gc` should be true. Signed-off-by: Winford --- src/libAtomVM/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libAtomVM/memory.c b/src/libAtomVM/memory.c index a2d3b91b8..7656c3e1e 100644 --- a/src/libAtomVM/memory.c +++ b/src/libAtomVM/memory.c @@ -167,7 +167,7 @@ enum MemoryGCResult memory_ensure_free_with_roots(Context *c, size_t size, size_ should_gc = ((alloc_mode == MEMORY_CAN_SHRINK) && free_space - size > maximum_free_space); } break; case MinimumHeapGrowth: - should_gc = ((alloc_mode == MEMORY_CAN_SHRINK) && free_space - size > 0); + should_gc = ((alloc_mode == MEMORY_CAN_SHRINK) && free_space - size == 0); break; case FibonacciHeapGrowth: { memory_size = memory_heap_memory_size(&c->heap);