Skip to content

Commit d82aed5

Browse files
committed
Desktop (Windows): read env and open the configstore via UTF-16 APIs
USERPROFILE / HOME / XDG_CONFIG_HOME can contain characters outside the ANSI code page. Read them with _wgetenv and open the file with a wide path, converting to and from UTF-8 with wstring_convert as app_desktop.cc and heartbeat_storage_desktop.cc already do. Conversion failures yield an empty string rather than throwing.
1 parent 70a5b71 commit d82aed5

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎app_check/src/desktop/debug_provider_desktop.cc‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
#include "app_check/src/desktop/debug_provider_desktop.h"
1616

1717
#include <cerrno>
18+
#include <codecvt>
1819
#include <cstdint>
1920
#include <cstdio>
2021
#include <cstdlib>
2122
#include <fstream>
2223
#include <iterator>
24+
#include <locale>
2325
#include <map>
2426
#include <memory>
2527
#include <string>
@@ -60,9 +62,23 @@ std::string GenerateUuidString() {
6062
return std::string(uuid_str);
6163
}
6264

65+
#if FIREBASE_PLATFORM_WINDOWS
66+
// Windows paths can contain characters outside the ANSI code page, so the
67+
// environment is read and files are opened through the UTF-16 APIs. A failed
68+
// conversion yields an empty string instead of throwing.
69+
using Utf8Utf16Converter =
70+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>;
71+
#endif // FIREBASE_PLATFORM_WINDOWS
72+
6373
std::string GetNonEmptyEnv(const char* name) {
74+
#if FIREBASE_PLATFORM_WINDOWS
75+
Utf8Utf16Converter converter("", L"");
76+
const wchar_t* val = _wgetenv(converter.from_bytes(name).c_str());
77+
return val != nullptr ? converter.to_bytes(val) : "";
78+
#else
6479
const char* val = std::getenv(name);
6580
return val != nullptr ? std::string(val) : "";
81+
#endif // FIREBASE_PLATFORM_WINDOWS
6682
}
6783

6884
std::vector<std::string> ResolveConfigstorePaths() {
@@ -93,7 +109,12 @@ std::string ResolveDebugTokenFromConfig(const std::string& config_path,
93109
const std::string& app_id) {
94110
if (config_path.empty() || app_id.empty()) return "";
95111
errno = 0;
112+
#if FIREBASE_PLATFORM_WINDOWS
113+
std::ifstream infile(Utf8Utf16Converter("", L"").from_bytes(config_path),
114+
std::ios::binary);
115+
#else
96116
std::ifstream infile(config_path.c_str(), std::ios::binary);
117+
#endif // FIREBASE_PLATFORM_WINDOWS
97118
if (!infile.is_open()) {
98119
// ENOENT (file not created yet) stays silent so apps not using the CLI
99120
// flow do not log errors; other I/O failures are surfaced.

0 commit comments

Comments
 (0)