From fe900e057b6068b570582e6640894a7d504f1259 Mon Sep 17 00:00:00 2001 From: Itrimel Date: Fri, 7 Feb 2020 18:14:33 +0100 Subject: [PATCH] Core/GeckoCodeConfig : Fix Gecko codes formatting Some locales (e.g. fr_FR.UTF-8 on ArchLinux) don't split the string stream on a space. As such, when extracted formatted data from te stream, it will return the two numbers as one for the first call, effectively overflowing the u32 variable, then will do an out-of-bounds read for the second call. Forcing the use of the C locale on the streams where it would cause a problem allows to workaround this behavior. --- Source/Core/Core/GeckoCodeConfig.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/Core/Core/GeckoCodeConfig.cpp b/Source/Core/Core/GeckoCodeConfig.cpp index a096e722d2..7bf0e59c1f 100644 --- a/Source/Core/Core/GeckoCodeConfig.cpp +++ b/Source/Core/Core/GeckoCodeConfig.cpp @@ -85,6 +85,11 @@ std::vector DownloadCodes(std::string gametdb_id, bool* succeeded) { std::istringstream ssline(line); std::string addr, data; + + // Some locales (e.g. fr_FR.UTF-8) don't split the string stream on space + // Use the C locale to workaround this behavior + ssline.imbue(std::locale::classic()); + ssline >> addr >> data; ssline.seekg(0); @@ -139,6 +144,10 @@ std::vector LoadCodes(const IniFile& globalIni, const IniFile& localI { std::istringstream ss(line); + // Some locales (e.g. fr_FR.UTF-8) don't split the string stream on space + // Use the C locale to workaround this behavior + ss.imbue(std::locale::classic()); + switch ((line)[0]) { // enabled or disabled code