mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 05:45:05 +01:00
Merge #17482: util: Disallow network-qualified command line options
900d8f6f70
util: Disallow network-qualified command line options (Russell Yanofsky) Pull request description: Previously these were allowed but ignored. This change implements one of the settings simplifications listed in #17508. Change includes release notes. ACKs for top commit: laanwj: ACK900d8f6f70
Tree-SHA512: ab020a16a86c1e8ec709fbf798d533879d32c565eceeb7eb785c33042c49c6b4d1108c5453d8166e4a2abffc2c8802fbb6d3b895e0ddeefa8f274fd647e3c8ad
This commit is contained in:
commit
8a56f79d49
@ -104,6 +104,13 @@ Wallet
|
|||||||
Low-level changes
|
Low-level changes
|
||||||
=================
|
=================
|
||||||
|
|
||||||
|
Command line
|
||||||
|
------------
|
||||||
|
|
||||||
|
Command line options prefixed with main/test/regtest network names like
|
||||||
|
`-main.port=8333` `-test.server=1` previously were allowed but ignored. Now
|
||||||
|
they trigger "Invalid parameter" errors on startup.
|
||||||
|
|
||||||
Tests
|
Tests
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -340,6 +340,27 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters)
|
|||||||
BOOST_CHECK(testArgs.GetArgs("-ccc").size() == 2);
|
BOOST_CHECK(testArgs.GetArgs("-ccc").size() == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(util_ParseInvalidParameters)
|
||||||
|
{
|
||||||
|
TestArgsManager test;
|
||||||
|
test.SetupArgs({{"-registered", ArgsManager::ALLOW_ANY}});
|
||||||
|
|
||||||
|
const char* argv[] = {"ignored", "-registered"};
|
||||||
|
std::string error;
|
||||||
|
BOOST_CHECK(test.ParseParameters(2, (char**)argv, error));
|
||||||
|
BOOST_CHECK_EQUAL(error, "");
|
||||||
|
|
||||||
|
argv[1] = "-unregistered";
|
||||||
|
BOOST_CHECK(!test.ParseParameters(2, (char**)argv, error));
|
||||||
|
BOOST_CHECK_EQUAL(error, "Invalid parameter -unregistered");
|
||||||
|
|
||||||
|
// Make sure registered parameters prefixed with a chain name trigger errors.
|
||||||
|
// (Previously, they were accepted and ignored.)
|
||||||
|
argv[1] = "-test.registered";
|
||||||
|
BOOST_CHECK(!test.ParseParameters(2, (char**)argv, error));
|
||||||
|
BOOST_CHECK_EQUAL(error, "Invalid parameter -test.registered");
|
||||||
|
}
|
||||||
|
|
||||||
static void TestParse(const std::string& str, bool expected_bool, int64_t expected_int)
|
static void TestParse(const std::string& str, bool expected_bool, int64_t expected_int)
|
||||||
{
|
{
|
||||||
TestArgsManager test;
|
TestArgsManager test;
|
||||||
@ -835,7 +856,8 @@ struct ArgsMergeTestingSetup : public BasicTestingSetup {
|
|||||||
void ForEachMergeSetup(Fn&& fn)
|
void ForEachMergeSetup(Fn&& fn)
|
||||||
{
|
{
|
||||||
ActionList arg_actions = {};
|
ActionList arg_actions = {};
|
||||||
ForEachNoDup(arg_actions, SET, SECTION_NEGATE, [&] {
|
// command_line_options do not have sections. Only iterate over SET and NEGATE
|
||||||
|
ForEachNoDup(arg_actions, SET, NEGATE, [&] {
|
||||||
ActionList conf_actions = {};
|
ActionList conf_actions = {};
|
||||||
ForEachNoDup(conf_actions, SET, SECTION_NEGATE, [&] {
|
ForEachNoDup(conf_actions, SET, SECTION_NEGATE, [&] {
|
||||||
for (bool soft_set : {false, true}) {
|
for (bool soft_set : {false, true}) {
|
||||||
@ -995,7 +1017,7 @@ BOOST_FIXTURE_TEST_CASE(util_ArgsMerge, ArgsMergeTestingSetup)
|
|||||||
// Results file is formatted like:
|
// Results file is formatted like:
|
||||||
//
|
//
|
||||||
// <input> || <IsArgSet/IsArgNegated/GetArg output> | <GetArgs output> | <GetUnsuitable output>
|
// <input> || <IsArgSet/IsArgNegated/GetArg output> | <GetArgs output> | <GetUnsuitable output>
|
||||||
BOOST_CHECK_EQUAL(out_sha_hex, "b835eef5977d69114eb039a976201f8c7121f34fe2b7ea2b73cafb516e5c9dc8");
|
BOOST_CHECK_EQUAL(out_sha_hex, "8fd4877bb8bf337badca950ede6c917441901962f160e52514e06a60dea46cde");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similar test as above, but for ArgsManager::GetChainName function.
|
// Similar test as above, but for ArgsManager::GetChainName function.
|
||||||
|
@ -312,21 +312,18 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
|
|||||||
std::string section;
|
std::string section;
|
||||||
util::SettingsValue value = InterpretOption(section, key, val);
|
util::SettingsValue value = InterpretOption(section, key, val);
|
||||||
Optional<unsigned int> flags = GetArgFlags('-' + key);
|
Optional<unsigned int> flags = GetArgFlags('-' + key);
|
||||||
if (flags) {
|
|
||||||
if (!CheckValid(key, value, *flags, error)) {
|
// Unknown command line options and command line options with dot
|
||||||
return false;
|
// characters (which are returned from InterpretOption with nonempty
|
||||||
}
|
// section strings) are not valid.
|
||||||
// Weird behavior preserved for backwards compatibility: command
|
if (!flags || !section.empty()) {
|
||||||
// line options with section prefixes are allowed but ignored. It
|
error = strprintf("Invalid parameter %s", argv[i]);
|
||||||
// would be better if these options triggered the Invalid parameter
|
|
||||||
// error below.
|
|
||||||
if (section.empty()) {
|
|
||||||
m_settings.command_line_options[key].push_back(value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error = strprintf("Invalid parameter -%s", key);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CheckValid(key, value, *flags, error)) return false;
|
||||||
|
|
||||||
|
m_settings.command_line_options[key].push_back(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we do not allow -includeconf from command line
|
// we do not allow -includeconf from command line
|
||||||
|
@ -23,7 +23,7 @@ class ConfArgsTest(BitcoinTestFramework):
|
|||||||
conf.write('includeconf={}\n'.format(inc_conf_file_path))
|
conf.write('includeconf={}\n'.format(inc_conf_file_path))
|
||||||
|
|
||||||
self.nodes[0].assert_start_raises_init_error(
|
self.nodes[0].assert_start_raises_init_error(
|
||||||
expected_msg='Error: Error parsing command line arguments: Invalid parameter -dash_cli',
|
expected_msg='Error: Error parsing command line arguments: Invalid parameter -dash_cli=1',
|
||||||
extra_args=['-dash_cli=1'],
|
extra_args=['-dash_cli=1'],
|
||||||
)
|
)
|
||||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||||
|
Loading…
Reference in New Issue
Block a user