Skip to content

Commit 6a98836

Browse files
dipinhoraSeanTAllen
authored andcommitted
Fix invalid allocation bug in runtime that allows for segfaults (#2896)
Thanks to @malte for identifying the root cause of #2013. This PR fixes things so that if there's a request for a `size_t` sized allocation, it actually tries to allocate it instead of pretending that it allocated it while not actually allocating anything which results in memory clobbering and segfaults. resolves #2013
1 parent 65f4ce1 commit 6a98836

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/libponyrt/mem/pool.c

+4
Original file line numberDiff line numberDiff line change
@@ -1052,5 +1052,9 @@ size_t ponyint_pool_adjust_size(size_t size)
10521052
if((size & POOL_ALIGN_MASK) != 0)
10531053
size = (size & ~POOL_ALIGN_MASK) + POOL_ALIGN;
10541054

1055+
// we've overflowed the `size_t` datatype
1056+
if(size == 0)
1057+
size = size - 1;
1058+
10551059
return size;
10561060
}

0 commit comments

Comments
 (0)