all repos — mgba @ b1a484bb5a679c2b7de1a373530bb24dd1327419

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

b1a484bb5a679c2b7de1a373530bb24dd1327419

parent

9c321c30c2b5d0d5c0ca43a21e308361937e2580

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

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

@@ -66,6 +66,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);

@@ -80,7 +83,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); }