mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 07:39:08 +01:00
refactor: Block unsafe fs::path std::string conversion calls
There is no change in behavior. This just helps prepare for the transition from boost::filesystem to std::filesystem by avoiding calls to methods which will be unsafe after the transaction to std::filesystem to due lack of a boost::filesystem::path::imbue equivalent and inability to set a predictable locale. Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Co-authored-by: Kiminuo <kiminuo@protonmail.com> Co-authored-by: MarcoFalke <falke.marco@gmail.com>
This commit is contained in:
@@ -66,24 +66,24 @@ bool ReadSettings(const fs::path& path, std::map<std::string, SettingsValue>& va
|
||||
fsbridge::ifstream file;
|
||||
file.open(path);
|
||||
if (!file.is_open()) {
|
||||
errors.emplace_back(strprintf("%s. Please check permissions.", path.string()));
|
||||
errors.emplace_back(strprintf("%s. Please check permissions.", fs::PathToString(path)));
|
||||
return false;
|
||||
}
|
||||
|
||||
SettingsValue in;
|
||||
if (!in.read(std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()})) {
|
||||
errors.emplace_back(strprintf("Unable to parse settings file %s", path.string()));
|
||||
errors.emplace_back(strprintf("Unable to parse settings file %s", fs::PathToString(path)));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.fail()) {
|
||||
errors.emplace_back(strprintf("Failed reading settings file %s", path.string()));
|
||||
errors.emplace_back(strprintf("Failed reading settings file %s", fs::PathToString(path)));
|
||||
return false;
|
||||
}
|
||||
file.close(); // Done with file descriptor. Release while copying data.
|
||||
|
||||
if (!in.isObject()) {
|
||||
errors.emplace_back(strprintf("Found non-object value %s in settings file %s", in.write(), path.string()));
|
||||
errors.emplace_back(strprintf("Found non-object value %s in settings file %s", in.write(), fs::PathToString(path)));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ bool ReadSettings(const fs::path& path, std::map<std::string, SettingsValue>& va
|
||||
for (size_t i = 0; i < in_keys.size(); ++i) {
|
||||
auto inserted = values.emplace(in_keys[i], in_values[i]);
|
||||
if (!inserted.second) {
|
||||
errors.emplace_back(strprintf("Found duplicate key %s in settings file %s", in_keys[i], path.string()));
|
||||
errors.emplace_back(strprintf("Found duplicate key %s in settings file %s", in_keys[i], fs::PathToString(path)));
|
||||
}
|
||||
}
|
||||
return errors.empty();
|
||||
@@ -109,7 +109,7 @@ bool WriteSettings(const fs::path& path,
|
||||
fsbridge::ofstream file;
|
||||
file.open(path);
|
||||
if (file.fail()) {
|
||||
errors.emplace_back(strprintf("Error: Unable to open settings file %s for writing", path.string()));
|
||||
errors.emplace_back(strprintf("Error: Unable to open settings file %s for writing", fs::PathToString(path)));
|
||||
return false;
|
||||
}
|
||||
file << out.write(/* prettyIndent= */ 1, /* indentLevel= */ 4) << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user