Qt: Actually bounds check memory block index
Vicki Pfau vi@endrift.com
Mon, 02 Nov 2020 01:01:17 -0800
1 files changed,
8 insertions(+),
1 deletions(-)
jump to
M
src/platform/qt/MemoryView.cpp
→
src/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); }