mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-03 00:39:02 +00:00
Make JSON reading safer
- Check that the file actually opened before reading it - If the JSON was discarded, then make just use an empty object
This commit is contained in:
+12
-4
@@ -42,14 +42,22 @@ void Lang::load(const std::string &lang) {
|
||||
/* Check if exist. */
|
||||
if (access(("romfs:/lang/" + lang + "/app.json").c_str(), F_OK) == 0) {
|
||||
values = fopen(("romfs:/lang/" + lang + "/app.json").c_str(), "rt");
|
||||
appJson = nlohmann::json::parse(values, nullptr, false);
|
||||
fclose(values);
|
||||
if (values) {
|
||||
appJson = nlohmann::json::parse(values, nullptr, false);
|
||||
fclose(values);
|
||||
}
|
||||
if (appJson.is_discarded())
|
||||
appJson = { };
|
||||
return;
|
||||
|
||||
} else {
|
||||
values = fopen("romfs:/lang/en/app.json", "rt");
|
||||
appJson = nlohmann::json::parse(values, nullptr, false);
|
||||
fclose(values);
|
||||
if (values) {
|
||||
appJson = nlohmann::json::parse(values, nullptr, false);
|
||||
fclose(values);
|
||||
}
|
||||
if (appJson.is_discarded())
|
||||
appJson = { };
|
||||
return;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user