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.
This commit is contained in:
Itrimel 2020-02-07 18:14:33 +01:00
parent a205ecb446
commit fe900e057b
1 changed files with 9 additions and 0 deletions

View File

@ -85,6 +85,11 @@ std::vector<GeckoCode> 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<GeckoCode> 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