|
16 | 16 | #include <algorithm> |
17 | 17 | #include <cassert> |
18 | 18 | #include <cstdlib> |
| 19 | +#include <filesystem> |
19 | 20 | #include <fstream> |
20 | 21 | #include <iostream> |
21 | 22 | #include <list> |
@@ -130,6 +131,10 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) |
130 | 131 | const auto conf_path{GetConfigFilePath()}; |
131 | 132 | std::ifstream stream; |
132 | 133 | if (!conf_path.empty()) { // path is empty when -noconf is specified |
| 134 | + if (fs::is_directory(conf_path)) { |
| 135 | + error = strprintf("Config file \"%s\" is a directory.", fs::PathToString(conf_path)); |
| 136 | + return false; |
| 137 | + } |
133 | 138 | stream = std::ifstream{conf_path}; |
134 | 139 | // If the file is explicitly specified, it must be readable |
135 | 140 | if (IsArgSet("-conf") && !stream.good()) { |
@@ -177,7 +182,12 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) |
177 | 182 | const size_t default_includes = add_includes({}); |
178 | 183 |
|
179 | 184 | for (const std::string& conf_file_name : conf_file_names) { |
180 | | - std::ifstream conf_file_stream{AbsPathForConfigVal(*this, fs::PathFromString(conf_file_name), /*net_specific=*/false)}; |
| 185 | + const auto include_conf_path{AbsPathForConfigVal(*this, fs::PathFromString(conf_file_name), /*net_specific=*/false)}; |
| 186 | + if (fs::is_directory(include_conf_path)) { |
| 187 | + error = strprintf("Included config file \"%s\" is a directory.", fs::PathToString(include_conf_path)); |
| 188 | + return false; |
| 189 | + } |
| 190 | + std::ifstream conf_file_stream{include_conf_path}; |
181 | 191 | if (conf_file_stream.good()) { |
182 | 192 | if (!ReadConfigStream(conf_file_stream, conf_file_name, error, ignore_invalid_keys)) { |
183 | 193 | return false; |
|
0 commit comments