Skip to content

Commit bd2e2d5

Browse files
committed
Merge #1012: fuzz: backport fixes to fuzzer errors
0896d0a util: Properly handle -noincludeconf on command line (MarcoFalke) 5f18d33 Cleanup -includeconf error message (MarcoFalke) 99b8659 Fix crash when parsing command line with -noincludeconf=0 (MarcoFalke) c98902b fuzz: add missing ECCVerifyHandle to base_encode_decode (Andrew Poelstra) Pull request description: Backport of bitcoin/bitcoin#22279 and bitcoin/bitcoin#22002 and bitcoin/bitcoin#22137 ACKs for top commit: jonasnick: utACK 0896d0a Tree-SHA512: 7a9c4a20fc51ac3e66fd0b8d6f28200b9342774fcb003c561e277fab4a68c3ebd2cab4c3081170199a51aabf3956e0f7248fa6c853c8aa971645fb9039adc688
2 parents eda3fbe + 0896d0a commit bd2e2d5

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/test/fuzz/base_encode_decode.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
#include <string>
1515
#include <vector>
1616

17+
void initialize()
18+
{
19+
static const ECCVerifyHandle verify_handle;
20+
}
21+
1722
void test_one_input(const std::vector<uint8_t>& buffer)
1823
{
1924
const std::string random_encoded_string(buffer.begin(), buffer.end());

src/test/util_tests.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,25 @@ BOOST_FIXTURE_TEST_CASE(util_CheckValue, CheckValueTest)
318318
CheckValue(M::ALLOW_ANY, "-value=abc", Expect{"abc"}.String("abc").Int(0).Bool(false).List({"abc"}));
319319
}
320320

321+
struct NoIncludeConfTest {
322+
std::string Parse(const char* arg)
323+
{
324+
TestArgsManager test;
325+
test.SetupArgs({{"-includeconf", ArgsManager::ALLOW_ANY}});
326+
std::array<const char*, 2> argv{"ignored", arg};
327+
std::string error;
328+
(void)test.ParseParameters(argv.size(), argv.data(), error);
329+
return error;
330+
}
331+
};
332+
333+
BOOST_FIXTURE_TEST_CASE(util_NoIncludeConf, NoIncludeConfTest)
334+
{
335+
BOOST_CHECK_EQUAL(Parse("-noincludeconf"), "");
336+
BOOST_CHECK_EQUAL(Parse("-includeconf"), "-includeconf cannot be used from commandline; -includeconf=\"\"");
337+
BOOST_CHECK_EQUAL(Parse("-includeconf=file"), "-includeconf cannot be used from commandline; -includeconf=\"file\"");
338+
}
339+
321340
BOOST_AUTO_TEST_CASE(util_ParseParameters)
322341
{
323342
TestArgsManager testArgs;

src/util/system.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,16 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
324324
m_settings.command_line_options[key].push_back(value);
325325
}
326326

327-
// we do not allow -includeconf from command line
328-
bool success = true;
327+
// we do not allow -includeconf from command line, only -noincludeconf
329328
if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
330-
for (const auto& include : util::SettingsSpan(*includes)) {
331-
error += "-includeconf cannot be used from commandline; -includeconf=" + include.get_str() + "\n";
332-
success = false;
329+
const util::SettingsSpan values{*includes};
330+
// Range may be empty if -noincludeconf was passed
331+
if (!values.empty()) {
332+
error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write();
333+
return false; // pick first value as example
333334
}
334335
}
335-
return success;
336+
return true;
336337
}
337338

338339
Optional<unsigned int> ArgsManager::GetArgFlags(const std::string& name) const

test/functional/feature_includeconf.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ def run_test(self):
4343

4444
self.log.info("-includeconf cannot be used as command-line arg")
4545
self.stop_node(0)
46-
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")
46+
self.nodes[0].assert_start_raises_init_error(
47+
extra_args=['-noincludeconf=0'],
48+
expected_msg='Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf=true',
49+
)
50+
self.nodes[0].assert_start_raises_init_error(
51+
extra_args=['-includeconf=relative2.conf', '-includeconf=no_warn.conf'],
52+
expected_msg='Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf="relative2.conf"',
53+
)
4754

4855
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
4956
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f:

0 commit comments

Comments
 (0)