Correctly open files with non-ASCII paths on Windows

This fixes #976, fixes #974, fixes #444.

On Windows the standard stream open() functions expect bytes encoded in
current system encoding, not UTF8. Since we're dealing with UTF8
throughout the application this results in wrong paths being passed and
failure to open files. As a solution, we convert the paths to UTF16 via
the WCHAR character type and use the special Windows-specific overloads
of open() functions.
This commit is contained in:
Povilas Kanapickas
2021-10-30 00:52:57 +03:00
parent 8286c85dc0
commit d24f368efe
7 changed files with 111 additions and 4 deletions

View File

@@ -25,6 +25,7 @@
#include "base/Log.h"
#include "base/String.h"
#include "common/DataDirectories.h"
#include "io/fstream.h"
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -708,7 +709,7 @@ SecureSocket::verifyCertFingerprint()
// check if this fingerprint exist
std::string fileLine;
std::ifstream file;
file.open(trustedServersFilename.c_str());
barrier::open_utf8_path(file, trustedServersFilename);
if (!file.is_open()) {
LOG((CLOG_NOTE "Unable to open trustedServersFile: %s", trustedServersFilename.c_str() ));