Auto merge of #4583 - oxarbitrage:issue4495, r=str4d

Check for config options that may be duplicated in the config file

`ReadConfigFile()` now enforces that only a subset of config options may be duplicated. CLI behaviour is unaltered.

Closes https://github.com/zcash/zcash/issues/4495
This commit is contained in:
Homu 2020-07-31 15:59:13 +00:00
commit bded4ca502
1 changed files with 27 additions and 0 deletions

View File

@ -627,10 +627,37 @@ void ReadConfigFile(const std::string& confPath,
set<string> setOptions;
setOptions.insert("*");
const vector<string> allowed_duplicates = {
"addnode",
"bind",
"connect",
"debug",
"externalip",
"fundingstream",
"loadblock",
"onlynet",
"rpcallowip",
"rpcauth",
"rpcbind",
"seednode",
"uacomment",
"whitebind",
"whitelist"
};
set<string> unique_options;
for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
{
string strKey = string("-") + it->string_key;
string strValue = it->value[0];
if (find(allowed_duplicates.begin(), allowed_duplicates.end(), it->string_key) == allowed_duplicates.end())
{
if (!unique_options.insert(strKey).second) {
throw std::runtime_error(strprintf("Option '%s' is duplicated, which is not allowed.", strKey));
}
}
InterpretNegativeSetting(strKey, strValue);
// Don't overwrite existing settings so command line settings override zcash.conf
if (mapSettingsRet.count(strKey) == 0)