Fix potential memory corruption when execution malformed ROMs

This commit is contained in:
Lior Halphon 2020-06-03 20:54:06 +03:00
parent 9e8b4345c0
commit 6a3cd371d0
1 changed files with 4 additions and 1 deletions

View File

@ -135,7 +135,10 @@ void GB_configure_cart(GB_gameboy_t *gb)
static const unsigned ram_sizes[256] = {0, 0x800, 0x2000, 0x8000, 0x20000, 0x10000}; static const unsigned ram_sizes[256] = {0, 0x800, 0x2000, 0x8000, 0x20000, 0x10000};
gb->mbc_ram_size = ram_sizes[gb->rom[0x149]]; gb->mbc_ram_size = ram_sizes[gb->rom[0x149]];
} }
if (gb->mbc_ram_size) {
gb->mbc_ram = malloc(gb->mbc_ram_size); gb->mbc_ram = malloc(gb->mbc_ram_size);
}
/* Todo: Some games assume unintialized MBC RAM is 0xFF. It this true for all cartridges types? */ /* Todo: Some games assume unintialized MBC RAM is 0xFF. It this true for all cartridges types? */
memset(gb->mbc_ram, 0xFF, gb->mbc_ram_size); memset(gb->mbc_ram, 0xFF, gb->mbc_ram_size);