From c5357fa4151e1ac90427ae0493a7bb3e451f8de5 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Fri, 18 Jun 2021 23:13:07 +0000 Subject: fuzz: add missing ECCVerifyHandle to base_encode_decode GitHub Pull: #22279 Rebased-From: 906d7913117c8f10934b37afa27ae8ac565da042 --- src/test/fuzz/base_encode_decode.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/fuzz/base_encode_decode.cpp b/src/test/fuzz/base_encode_decode.cpp index 8d49f93c2f..f7b1a03007 100644 --- a/src/test/fuzz/base_encode_decode.cpp +++ b/src/test/fuzz/base_encode_decode.cpp @@ -14,6 +14,11 @@ #include #include +void initialize() +{ + static const ECCVerifyHandle verify_handle; +} + void test_one_input(const std::vector& buffer) { const std::string random_encoded_string(buffer.begin(), buffer.end()); -- cgit v1.2.3 From 70eac6fcd02b6c44cb4b1f2fb895eae147e3f490 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 21 May 2021 10:52:46 +0200 Subject: Fix crash when parsing command line with -noincludeconf=0 Github-Pull: #22002 Rebased-From: fa9f711c3746ca3962f15224285a453744cd45b3 --- src/util/system.cpp | 2 +- test/functional/feature_includeconf.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/util/system.cpp b/src/util/system.cpp index 5f30136fa2..3512bb8bff 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -340,7 +340,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin bool success = true; if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) { for (const auto& include : util::SettingsSpan(*includes)) { - error += "-includeconf cannot be used from commandline; -includeconf=" + include.get_str() + "\n"; + error += "-includeconf cannot be used from commandline; -includeconf=" + include.write() + "\n"; success = false; } } diff --git a/test/functional/feature_includeconf.py b/test/functional/feature_includeconf.py index 6f1a0cd348..8eb20adf5b 100755 --- a/test/functional/feature_includeconf.py +++ b/test/functional/feature_includeconf.py @@ -43,7 +43,14 @@ class IncludeConfTest(BitcoinTestFramework): self.log.info("-includeconf cannot be used as command-line arg") self.stop_node(0) - self.nodes[0].assert_start_raises_init_error(extra_args=["-includeconf=relative2.conf"], expected_msg="Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf=relative2.conf") + self.nodes[0].assert_start_raises_init_error( + extra_args=['-noincludeconf=0'], + expected_msg='Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf=true', + ) + self.nodes[0].assert_start_raises_init_error( + extra_args=['-includeconf=relative2.conf'], + expected_msg='Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf="relative2.conf"', + ) self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'") with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f: -- cgit v1.2.3 From 513613d8a87337f1d1f639bc9426165c3b6be62e Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 20 May 2021 13:46:15 +0200 Subject: Cleanup -includeconf error message Remove the erroneous trailing newline '\n'. Also, print only the first value to remove needless redundancy in the error message. Github-Pull: #22002 Rebased-From: fad0867d6ab9430070aa7d60bf7617a6508e0586 --- src/util/system.cpp | 10 ++++------ test/functional/feature_includeconf.py | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/util/system.cpp b/src/util/system.cpp index 3512bb8bff..a21d58a19d 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -337,14 +337,12 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin } // we do not allow -includeconf from command line - bool success = true; if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) { - for (const auto& include : util::SettingsSpan(*includes)) { - error += "-includeconf cannot be used from commandline; -includeconf=" + include.write() + "\n"; - success = false; - } + const auto& include{*util::SettingsSpan(*includes).begin()}; // pick first value as example + error = "-includeconf cannot be used from commandline; -includeconf=" + include.write(); + return false; } - return success; + return true; } Optional ArgsManager::GetArgFlags(const std::string& name) const diff --git a/test/functional/feature_includeconf.py b/test/functional/feature_includeconf.py index 8eb20adf5b..6a1f3b0ef1 100755 --- a/test/functional/feature_includeconf.py +++ b/test/functional/feature_includeconf.py @@ -48,7 +48,7 @@ class IncludeConfTest(BitcoinTestFramework): expected_msg='Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf=true', ) self.nodes[0].assert_start_raises_init_error( - extra_args=['-includeconf=relative2.conf'], + extra_args=['-includeconf=relative2.conf', '-includeconf=no_warn.conf'], expected_msg='Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf="relative2.conf"', ) -- cgit v1.2.3 From da816247f0c00e1644f7ebe2b848cfd6a5c7026e Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 3 Jun 2021 12:14:33 +0200 Subject: util: Properly handle -noincludeconf on command line This bug was introduced in commit fad0867d6ab9430070aa7d60bf7617a6508e0586. Unit test Co-Authored-By: Russell Yanofsky Github-Pull: #22137 Rebased-From: fa910b47656d0e69cccb1f31804f2b11aa45d053 --- src/test/util_tests.cpp | 19 +++++++++++++++++++ src/util/system.cpp | 11 +++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 010b6adf1f..cc58f64555 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -318,6 +318,25 @@ BOOST_FIXTURE_TEST_CASE(util_CheckValue, CheckValueTest) CheckValue(M::ALLOW_ANY, "-value=abc", Expect{"abc"}.String("abc").Int(0).Bool(false).List({"abc"})); } +struct NoIncludeConfTest { + std::string Parse(const char* arg) + { + TestArgsManager test; + test.SetupArgs({{"-includeconf", ArgsManager::ALLOW_ANY}}); + std::array argv{"ignored", arg}; + std::string error; + (void)test.ParseParameters(argv.size(), argv.data(), error); + return error; + } +}; + +BOOST_FIXTURE_TEST_CASE(util_NoIncludeConf, NoIncludeConfTest) +{ + BOOST_CHECK_EQUAL(Parse("-noincludeconf"), ""); + BOOST_CHECK_EQUAL(Parse("-includeconf"), "-includeconf cannot be used from commandline; -includeconf=\"\""); + BOOST_CHECK_EQUAL(Parse("-includeconf=file"), "-includeconf cannot be used from commandline; -includeconf=\"file\""); +} + BOOST_AUTO_TEST_CASE(util_ParseParameters) { TestArgsManager testArgs; diff --git a/src/util/system.cpp b/src/util/system.cpp index a21d58a19d..0d8b669b79 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -336,11 +336,14 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin 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, only -noincludeconf if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) { - const auto& include{*util::SettingsSpan(*includes).begin()}; // pick first value as example - error = "-includeconf cannot be used from commandline; -includeconf=" + include.write(); - return false; + const util::SettingsSpan values{*includes}; + // Range may be empty if -noincludeconf was passed + if (!values.empty()) { + error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write(); + return false; // pick first value as example + } } return true; } -- cgit v1.2.3