From bba65b8a8205917c678ef52416da833a45a639bc Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 24 May 2023 19:34:23 +1000 Subject: [PATCH] Patch: Discard patches with non-hex addresses/values --- pcsx2/Patch.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/pcsx2/Patch.cpp b/pcsx2/Patch.cpp index 5474242755..a3ff054e96 100644 --- a/pcsx2/Patch.cpp +++ b/pcsx2/Patch.cpp @@ -245,21 +245,39 @@ namespace PatchFunc return; } + std::string_view placetopatch_end; + const std::optional placetopatch = StringUtil::FromChars(pieces[0], 10, &placetopatch_end); + IniPatch iPatch = {0}; iPatch.enabled = 0; iPatch.placetopatch = StringUtil::FromChars(pieces[0]).value_or(_PPT_END_MARKER); - if (iPatch.placetopatch >= _PPT_END_MARKER) + if (!placetopatch.has_value() || !placetopatch_end.empty() || + (iPatch.placetopatch = placetopatch.value()) >= _PPT_END_MARKER) { PATCH_ERROR("Invalid 'place' value '%.*s' (0 - once on startup, 1: continuously)", static_cast(pieces[0].size()), pieces[0].data()); return; } + std::string_view addr_end, data_end; + const std::optional addr = StringUtil::FromChars(pieces[2], 16, &addr_end); + const std::optional data = StringUtil::FromChars(pieces[4], 16, &data_end); + if (!addr.has_value() || !addr_end.empty()) + { + PATCH_ERROR("Malformed address '%.*s', a hex number is expected", static_cast(pieces[2].size()), pieces[2].data()); + return; + } + else if (!data.has_value() || !data_end.empty()) + { + PATCH_ERROR("Malformed data '%.*s', a hex number is expected", static_cast(pieces[4].size()), pieces[4].data()); + return; + } + iPatch.cpu = (patch_cpu_type)PatchTableExecute(pieces[1], std::string_view(), cpuCore); - iPatch.addr = StringUtil::FromChars(pieces[2], 16).value_or(0); + iPatch.addr = addr.value(); iPatch.type = (patch_data_type)PatchTableExecute(pieces[3], std::string_view(), dataType); - iPatch.data = StringUtil::FromChars(pieces[4], 16).value_or(0); + iPatch.data = data.value(); if (iPatch.cpu == 0) {