From 6a3cd371d01e5d253b0ab999da53d87ac84ab7cc Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 3 Jun 2020 20:54:06 +0300 Subject: [PATCH] Fix potential memory corruption when execution malformed ROMs --- Core/mbc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Core/mbc.c b/Core/mbc.c index 72073f6..ba5055f 100644 --- a/Core/mbc.c +++ b/Core/mbc.c @@ -135,7 +135,10 @@ void GB_configure_cart(GB_gameboy_t *gb) static const unsigned ram_sizes[256] = {0, 0x800, 0x2000, 0x8000, 0x20000, 0x10000}; gb->mbc_ram_size = ram_sizes[gb->rom[0x149]]; } - gb->mbc_ram = malloc(gb->mbc_ram_size); + + if (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? */ memset(gb->mbc_ram, 0xFF, gb->mbc_ram_size);