all repos — mgba @ 01e73bc15f11d759a3327fb37edddb07be54b6cc

mGBA Game Boy Advance Emulator

Qt: Actually bounds check memory block index
Vicki Pfau vi@endrift.com
Mon, 02 Nov 2020 01:01:17 -0800
commit

01e73bc15f11d759a3327fb37edddb07be54b6cc

parent

5a1e68beba0084182dbad7f1a457d93b38a49665

1 files changed, 8 insertions(+), 1 deletions(-)

jump to
M src/platform/qt/MemoryView.cppsrc/platform/qt/MemoryView.cpp

@@ -207,6 +207,9 @@ void MemoryView::setIndex(int index) {

mCore* core = m_controller->thread()->core; const mCoreMemoryBlock* blocks; size_t nBlocks = core->listMemoryBlocks(core, &blocks); + if (index < 0 || static_cast<size_t>(index) >= nBlocks) { + return; + } const mCoreMemoryBlock& info = blocks[index]; m_region = qMakePair(info.start, info.end);

@@ -221,7 +224,11 @@ void MemoryView::setSegment(int segment) {

mCore* core = m_controller->thread()->core; const mCoreMemoryBlock* blocks; size_t nBlocks = core->listMemoryBlocks(core, &blocks); - const mCoreMemoryBlock& info = blocks[m_ui.regions->currentIndex()]; + int index = m_ui.regions->currentIndex(); + if (index < 0 || static_cast<size_t>(index) >= nBlocks) { + return; + } + const mCoreMemoryBlock& info = blocks[index]; m_ui.hexfield->setSegment(info.maxSegment < segment ? info.maxSegment : segment); }