aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/util/system.cpp5
-rwxr-xr-xtest/functional/feature_config_args.py4
2 files changed, 9 insertions, 0 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 30d4103819..4e16a83c87 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -904,6 +904,11 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
const std::string confPath = GetArg("-conf", BITCOIN_CONF_FILENAME);
fsbridge::ifstream stream(GetConfigFile(confPath));
+ // not ok to have a config file specified that cannot be opened
+ if (IsArgSet("-conf") && !stream.good()) {
+ error = strprintf("specified config file \"%s\" could not be opened.", confPath);
+ return false;
+ }
// ok to not have a config file
if (stream.good()) {
if (!ReadConfigStream(stream, confPath, error, ignore_invalid_keys)) {
diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py
index d5f0ae480b..0daa0ba3d8 100755
--- a/test/functional/feature_config_args.py
+++ b/test/functional/feature_config_args.py
@@ -248,6 +248,10 @@ class ConfArgsTest(BitcoinTestFramework):
self.nodes[0].assert_start_raises_init_error([f'-conf={conf_file}'], f'Error: Error reading configuration file: specified data directory "{new_data_dir}" does not exist.')
+ # Check that an explicitly specified config file that cannot be opened fails
+ none_existent_conf_file = os.path.join(default_data_dir, "none_existent_bitcoin.conf")
+ self.nodes[0].assert_start_raises_init_error(['-conf=' + none_existent_conf_file], 'Error: Error reading configuration file: specified config file "' + none_existent_conf_file + '" could not be opened.')
+
# Create the directory and ensure the config file now works
os.mkdir(new_data_dir)
self.start_node(0, [f'-conf={conf_file}'])