all repos — mgba @ 37b1cbe29cd0814242168426dec17cf611414f2c

mGBA Game Boy Advance Emulator

Qt: Add additional checks in CheatModel to prevent crashes (fixes #163)
Jeffrey Pfau jeffrey@endrift.com
Wed, 11 Nov 2015 22:17:41 -0800
commit

37b1cbe29cd0814242168426dec17cf611414f2c

parent

770953a2169f84612aac7491c813662c33b72862

2 files changed, 10 insertions(+), 2 deletions(-)

jump to
M CHANGESCHANGES

@@ -25,6 +25,7 @@ - GBA Memory: Fix alignment of LDM/STM on SRAM

- GBA: Initialize uninitialized pristineRom and pristineRomSize members - GBA Memory: Fix unaligned out-of-bounds ROM loads - GBA: Fix warnings when creating and loading savestates + - Qt: Add additional checks in CheatModel to prevent crashes Misc: - Qt: Window size command line options are now supported - Qt: Increase usability of key mapper
M src/platform/qt/CheatsModel.cppsrc/platform/qt/CheatsModel.cpp

@@ -42,6 +42,10 @@ return QVariant();

} } + if (index.row() >= GBACheatSetsSize(&m_device->cheats)) { + return QVariant(); + } + int row = index.row(); const GBACheatSet* cheats = *GBACheatSetsGetPointer(&m_device->cheats, index.row()); switch (role) {

@@ -56,7 +60,7 @@ }

} bool CheatsModel::setData(const QModelIndex& index, const QVariant& value, int role) { - if (!index.isValid() || index.parent().isValid()) { + if (!index.isValid() || index.parent().isValid() || index.row() > GBACheatSetsSize(&m_device->cheats)) { return false; }

@@ -139,11 +143,14 @@ }

if (index.parent().isValid()) { return static_cast<GBACheatSet*>(index.internalPointer()); } + if (index.row() >= GBACheatSetsSize(&m_device->cheats)) { + return nullptr; + } return *GBACheatSetsGetPointer(&m_device->cheats, index.row()); } void CheatsModel::removeAt(const QModelIndex& index) { - if (!index.isValid() || index.parent().isValid()) { + if (!index.isValid() || index.parent().isValid() || index.row() >= GBACheatSetsSize(&m_device->cheats)) { return; } int row = index.row();