From 9fbcce689c5957c07563afaa706e871f48586735 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 24 Feb 2017 23:00:10 +0200 Subject: [PATCH] False positive stack overflow detection --- Tester/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Tester/main.c b/Tester/main.c index f60ce02..7aa8a03 100755 --- a/Tester/main.c +++ b/Tester/main.c @@ -20,7 +20,7 @@ static char *bmp_filename; static char *log_filename; static FILE *log_file; static void replace_extension(const char *src, size_t length, char *dest, const char *ext); -static bool push_start_a, start_is_not_first, a_is_bad, b_is_confirm, push_faster, push_slower, do_not_stop, push_a_twice, start_is_bad; +static bool push_start_a, start_is_not_first, a_is_bad, b_is_confirm, push_faster, push_slower, do_not_stop, push_a_twice, start_is_bad, allow_weird_sp_values; static unsigned int test_length = 60 * 40; GB_gameboy_t gb; @@ -87,7 +87,7 @@ static void vblank(GB_gameboy_t *gb) /* Detect common crashes and stop the test early */ if (frames < test_length - 1) { - if (gb->backtrace_size >= 0x200 || (gb->registers[GB_REGISTER_SP] >= 0xfe00 && gb->registers[GB_REGISTER_SP] < 0xff80)) { + if (gb->backtrace_size >= 0x200 || (!allow_weird_sp_values && (gb->registers[GB_REGISTER_SP] >= 0xfe00 && gb->registers[GB_REGISTER_SP] < 0xff80))) { GB_log(gb, "A stack overflow has probably occurred. (SP = $%04x; backtrace size = %d) \n", gb->registers[GB_REGISTER_SP], gb->backtrace_size); frames = test_length - 1; @@ -323,6 +323,9 @@ int main(int argc, char **argv) push_slower = strcmp((const char *)(gb.rom + 0x134), "BAKENOU") == 0; do_not_stop = strcmp((const char *)(gb.rom + 0x134), "SPACE INVADERS") == 0; + /* This game temporarily sets SP to OAM RAM */ + allow_weird_sp_values = strcmp((const char *)(gb.rom + 0x134), "WDL:TT") == 0; + /* Pressing start while in the map in Tsuri Sensi will leak an internal screen-stack which will eventually overflow, override an array of jump-table indexes, jump to a random address, execute an invalid opcode, and crash. Pressing A twice while slowing down