aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2019-01-18 19:01:02 +0200
committerRiccardo Spagni <ric@spagni.net>2019-01-18 19:01:02 +0200
commit416b6719bd22b2fc81b2b19c4919c7147d8b290b (patch)
treef95b4177c1f5aa392ebcfe10d7428b739899ae91
parentMerge pull request #5048 (diff)
parenti18n: filter LANG/LC_LANG for valid characters, and handle @ (diff)
downloadmonero-416b6719bd22b2fc81b2b19c4919c7147d8b290b.tar.xz
Merge pull request #5047
584126d1 i18n: filter LANG/LC_LANG for valid characters, and handle @ (moneromooo-monero)
-rw-r--r--src/common/i18n.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/common/i18n.cpp b/src/common/i18n.cpp
index ffe8d8b52..a32875945 100644
--- a/src/common/i18n.cpp
+++ b/src/common/i18n.cpp
@@ -38,6 +38,8 @@
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "i18n"
+#define MAX_LANGUAGE_SIZE 16
+
static const unsigned char qm_magic[16] = {0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95, 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd};
static std::map<std::string,std::string> i18n_entries;
@@ -62,7 +64,19 @@ std::string i18n_get_language()
std::string language = e;
language = language.substr(0, language.find("."));
+ language = language.substr(0, language.find("@"));
+
+ // check valid values
+ for (char c: language)
+ if (!strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@", c))
+ return "en";
+
std::transform(language.begin(), language.end(), language.begin(), tolower);
+ if (language.size() > MAX_LANGUAGE_SIZE)
+ {
+ i18n_log("Language from LANG/LC_ALL suspiciously long, defaulting to en");
+ return "en";
+ }
return language;
}