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 15, 2023
1 parent ae3317f commit 611096a
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 @@ -223,6 +223,15 @@ void CB2_TestRunner(void)
const struct MemBlock *block = head;
do
{
if (block->magic != MALLOC_SYSTEM_ID
|| !(EWRAM_START <= (uintptr_t)block->next && (uintptr_t)block->next < EWRAM_END)
|| (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 @@ -495,6 +504,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 @@ -528,6 +538,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 611096a

Please sign in to comment.