Skip to content

Commit

Permalink
Merge pull request #1528 from UncleGrumpy/codeql
Browse files Browse the repository at this point in the history
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 exceed 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.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
  • Loading branch information
bettio committed Feb 12, 2025
2 parents 9bf2202 + 116d14a commit 3fdfb77
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);
break;
case FibonacciHeapGrowth: {
memory_size = memory_heap_memory_size(&c->heap);
Expand Down

0 comments on commit 3fdfb77

Please sign in to comment.