mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
Disallow more unsafe string->path conversions allowed by path append operators
Add more fs::path operator/ and operator+ overloads to prevent unsafe string->path conversions on Windows that would cause strings to be decoded according to the current Windows locale & code page instead of the correct string encoding. Update application code to deal with loss of implicit string->path conversions by calling fs::u8path or fs::PathFromString explicitly, or by just changing variable types from std::string to fs::path to avoid conversions altoghther, or make them happen earlier. In all cases, there's no change in behavior either (1) because strings only contained ASCII characters and would be decoded the same regardless of what encoding was used, or (2) because of the 1:1 mapping between paths and strings using the PathToString and PathFromString functions. Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
This commit is contained in:
@@ -2049,7 +2049,7 @@ BOOST_AUTO_TEST_CASE(test_ParseFixedPoint)
|
||||
BOOST_CHECK(!ParseFixedPoint("31.999999999999999999999", 3, &amount));
|
||||
}
|
||||
|
||||
static void TestOtherThread(fs::path dirname, std::string lockname, bool *result)
|
||||
static void TestOtherThread(fs::path dirname, fs::path lockname, bool *result)
|
||||
{
|
||||
*result = LockDirectory(dirname, lockname);
|
||||
}
|
||||
@@ -2059,7 +2059,7 @@ static constexpr char LockCommand = 'L';
|
||||
static constexpr char UnlockCommand = 'U';
|
||||
static constexpr char ExitCommand = 'X';
|
||||
|
||||
[[noreturn]] static void TestOtherProcess(fs::path dirname, std::string lockname, int fd)
|
||||
[[noreturn]] static void TestOtherProcess(fs::path dirname, fs::path lockname, int fd)
|
||||
{
|
||||
char ch;
|
||||
while (true) {
|
||||
@@ -2090,7 +2090,7 @@ static constexpr char ExitCommand = 'X';
|
||||
BOOST_AUTO_TEST_CASE(test_LockDirectory)
|
||||
{
|
||||
fs::path dirname = m_args.GetDataDirBase() / "lock_dir";
|
||||
const std::string lockname = ".lock";
|
||||
const fs::path lockname = ".lock";
|
||||
#ifndef WIN32
|
||||
// Revert SIGCHLD to default, otherwise boost.test will catch and fail on
|
||||
// it: there is BOOST_TEST_IGNORE_SIGCHLD but that only works when defined
|
||||
|
||||
Reference in New Issue
Block a user