From f3724aef881ff2fdada98eddc792059e4e18c1c8 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 21 Nov 2015 10:13:10 +0000 Subject: Fix startup crash when using a locale boost does not like There are various locale related bugs in various versions of boost, where exceptions are thrown in boost::filesystem APIs when the current locale is not to boost's liking. It's not clear what "not to boost's liking" means in detail, though "en" and "en_US.UTF-8" are not to its liking. Fix it by running a test function that's known to throw in such a case, and resetting LANG and LC_ALL to C if an exception is thrown. In simplewallet, the locale is queried before that so the correct translations will still be used. --- src/common/util.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/common/util.cpp') 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 #endif +#include 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; + } } -- cgit v1.2.3