From baf351c3725a43cd90fc4fa3a8134fae9d5a1e8b Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 8 Nov 2017 17:48:33 -0800 Subject: [PATCH] Cheats: Clamp pointer command data to avail. In case more data is provided, as was allowed before. --- Core/CwCheat.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 8c548e082f..9dd18b3729 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -495,11 +495,11 @@ CheatOperation CWCheatEngine::InterpretNextCwCheat(const CheatCode &cheat, size_ addr = GetAddress(line1.part1 & 0x0FFFFFFF); if (i < cheat.lines.size()) { const CheatLine &line2 = cheat.lines[i++]; - const int count = line2.part1 & 0xFFFF; + int count = line2.part1 & 0xFFFF; - // Doesn't have enough lines to process. - if (i - 1 + count > cheat.lines.size()) - return { CheatOp::Invalid }; + // Clamp lines to process - previously allowed invalid counts. + if (i + count > cheat.lines.size()) + count = cheat.lines.size() - i; CheatOperation op = { CheatOp::CwCheatPointerCommands, addr, 0, arg }; op.pointerCommands.offset = (int)line2.part2;