Skip to content

Commit 3fdfb77

Browse files
committed
Merge pull request #1528 from UncleGrumpy/codeql
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
2 parents 9bf2202 + 116d14a commit 3fdfb77

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libAtomVM/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ enum MemoryGCResult memory_ensure_free_with_roots(Context *c, size_t size, size_
167167
should_gc = ((alloc_mode == MEMORY_CAN_SHRINK) && free_space - size > maximum_free_space);
168168
} break;
169169
case MinimumHeapGrowth:
170-
should_gc = ((alloc_mode == MEMORY_CAN_SHRINK) && free_space - size > 0);
170+
should_gc = ((alloc_mode == MEMORY_CAN_SHRINK) && free_space > size);
171171
break;
172172
case FibonacciHeapGrowth: {
173173
memory_size = memory_heap_memory_size(&c->heap);

0 commit comments

Comments
 (0)