fix(i18n): reject format-incompatible translations
Many strings are used directly as printf/ImGui format strings, and translations are loaded from user/installer-modifiable JSON with no validation. A translated value that drops or changes a conversion specifier would be passed to printf with mismatched varargs (undefined behavior) on a wallet screen. overlayTranslations() now compares each translated value's argument signature against the English source and keeps English on mismatch. Also adds the send_status_unconfirmed string used by the deferred-send-result path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
namespace dragonx {
|
||||
namespace util {
|
||||
@@ -58,7 +59,12 @@ public:
|
||||
private:
|
||||
I18n();
|
||||
void loadBuiltinEnglish();
|
||||
|
||||
// Overlay translated strings onto the English base, but reject any value whose printf
|
||||
// format-specifier signature differs from the English source (keep English instead).
|
||||
// Many strings are used directly as printf/ImGui format strings, so a mismatched
|
||||
// translation (dropped/changed specifier) is undefined behavior — this prevents it.
|
||||
void overlayTranslations(const nlohmann::json& translations);
|
||||
|
||||
std::string current_locale_ = "en";
|
||||
std::unordered_map<std::string, std::string> strings_;
|
||||
std::vector<std::pair<std::string, std::string>> available_languages_;
|
||||
|
||||
Reference in New Issue
Block a user