Skip to content

Commit 791f985

Browse files
committed
Merge bitcoin/bitcoin#22137: util: Properly handle -noincludeconf on command line (take 2)
fa910b4 util: Properly handle -noincludeconf on command line (MarcoFalke) Pull request description: Before: ``` $ ./src/qt/bitcoin-qt -noincludeconf (memory violation, can be observed with valgrind or similar) ``` After: ``` $ ./src/qt/bitcoin-qt -noincludeconf (passes startup) ``` Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34884 ACKs for top commit: practicalswift: cr ACK fa910b4: patch looks correct ryanofsky: Code review ACK fa910b4. Nice cleanups! Tree-SHA512: 5dfad82a78bca7a9a6bcc6aead2d7fbde166a09a5300a82f80dd1aee1de00e070bcb30b7472741a5396073b370898696e78c33038f94849219281d99358248ed
2 parents 260b1d7 + fa910b4 commit 791f985

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/test/util_tests.cpp

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

332+
struct NoIncludeConfTest {
333+
std::string Parse(const char* arg)
334+
{
335+
TestArgsManager test;
336+
test.SetupArgs({{"-includeconf", ArgsManager::ALLOW_ANY}});
337+
std::array argv{"ignored", arg};
338+
std::string error;
339+
(void)test.ParseParameters(argv.size(), argv.data(), error);
340+
return error;
341+
}
342+
};
343+
344+
BOOST_FIXTURE_TEST_CASE(util_NoIncludeConf, NoIncludeConfTest)
345+
{
346+
BOOST_CHECK_EQUAL(Parse("-noincludeconf"), "");
347+
BOOST_CHECK_EQUAL(Parse("-includeconf"), "-includeconf cannot be used from commandline; -includeconf=\"\"");
348+
BOOST_CHECK_EQUAL(Parse("-includeconf=file"), "-includeconf cannot be used from commandline; -includeconf=\"file\"");
349+
}
350+
332351
BOOST_AUTO_TEST_CASE(util_ParseParameters)
333352
{
334353
TestArgsManager testArgs;

src/util/system.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,14 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
365365
m_settings.command_line_options[key].push_back(value);
366366
}
367367

368-
// we do not allow -includeconf from command line
368+
// we do not allow -includeconf from command line, only -noincludeconf
369369
if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
370-
const auto& include{*util::SettingsSpan(*includes).begin()}; // pick first value as example
371-
error = "-includeconf cannot be used from commandline; -includeconf=" + include.write();
372-
return false;
370+
const util::SettingsSpan values{*includes};
371+
// Range may be empty if -noincludeconf was passed
372+
if (!values.empty()) {
373+
error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write();
374+
return false; // pick first value as example
375+
}
373376
}
374377
return true;
375378
}

0 commit comments

Comments
 (0)