Skip to content

Commit

Permalink
Fix comparison between unsigned subtraction and the value 0
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
UncleGrumpy committed Feb 10, 2025
1 parent 174fe85 commit c13a97e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libAtomVM/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c13a97e

Please sign in to comment.