Skip to content

Commit

Permalink
Prevent corrupted heaps causing infinite loops
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgriffin committed Jul 14, 2023
1 parent f0da7c4 commit 34378af
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/test_runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ void CB2_TestRunner(void)
const struct MemBlock *block = head;
do
{
if (block->magic != MALLOC_SYSTEM_ID
|| ((uintptr_t)block->next & 0x0F000000) != 0x02000000
|| (block->next <= block && block->next != head))
{
MgbaPrintf_("gHeap corrupted block at 0x%p", block);
gTestRunnerState.result = TEST_RESULT_ERROR;
break;
}

if (block->allocated)
{
const char *location = MemBlockLocation(block);
Expand Down Expand Up @@ -484,6 +493,7 @@ static s32 MgbaVPrintf_(const char *fmt, va_list va)
{
s32 i = 0;
s32 c, d;
u32 p;
const char *s;
while (*fmt)
{
Expand Down Expand Up @@ -517,6 +527,20 @@ static s32 MgbaVPrintf_(const char *fmt, va_list va)
i = MgbaPutchar_(i, buffer[--n]);
}
break;
case 'p':
p = va_arg(va, unsigned);
{
s32 n;
for (n = 0; n < 7; n++)
{
unsigned nybble = (p >> (24 - (4*n))) & 0xF;
if (nybble <= 9)
i = MgbaPutchar_(i, '0' + nybble);
else
i = MgbaPutchar_(i, 'a' + nybble - 10);
}
}
break;
case 'q':
d = va_arg(va, int);
{
Expand Down

0 comments on commit 34378af

Please sign in to comment.