diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.cpp | 19 | ||||
-rw-r--r-- | src/common/util.h | 2 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/common/util.cpp b/src/common/util.cpp index 7d39bc4f4..4c1b44004 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -43,6 +43,7 @@ using namespace epee; #else #include <sys/utsname.h> #endif +#include <boost/filesystem.hpp> namespace tools @@ -389,4 +390,22 @@ std::string get_nix_version_display_string() #endif return std::error_code(code, std::system_category()); } + + bool sanitize_locale() + { + // boost::filesystem throws for "invalid" locales, such as en_US.UTF-8, or kjsdkfs, + // so reset it here before any calls to it + try + { + boost::filesystem::path p {std::string("test")}; + p /= std::string("test"); + } + catch (...) + { + setenv("LC_ALL", "C", 1); + setenv("LANG", "C", 1); + return true; + } + return false; + } } diff --git a/src/common/util.h b/src/common/util.h index 883fe1e0f..236a0b6f0 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -88,6 +88,8 @@ namespace tools */ std::error_code replace_file(const std::string& replacement_name, const std::string& replaced_name); + bool sanitize_locale(); + inline crypto::hash get_proof_of_trust_hash(const nodetool::proof_of_trust& pot) { std::string s; |