util: Properly handle -noincludeconf on command line (take 2) #22137

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2106-utilTake2 changing 2 files +26 −4
  1. MarcoFalke commented at 9:55 AM on June 3, 2021: member

    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

  2. fanquake added the label Utils/log/libs on Jun 3, 2021
  3. in src/util/system.cpp:368 in fa2fc70ade outdated
     366 | @@ -367,9 +367,10 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
     367 |  
     368 |      // we do not allow -includeconf from command line
    


    ryanofsky commented at 11:49 AM on June 3, 2021:

    In commit "util: Properly handle -noincludeconf on command line" (fa2fc70adefda51913b714993931e281a67de5e0)

    Since it's not obvious how the -noincludeconf case is relevant to this loop (and it already caused a bug) it would be good to mention it in comments. Maybe:

    --- a/src/util/system.cpp
    +++ b/src/util/system.cpp
    @@ -365,8 +365,9 @@ 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")) {
    +        // Range will be empty in -noincludeconf case
             for (const auto& include : util::SettingsSpan(*includes)) {
                 error = "-includeconf cannot be used from commandline; -includeconf=" + include.write();
                 return false; // pick first value as example
    
    
    

    MarcoFalke commented at 12:14 PM on June 3, 2021:

    Thanks, fixed

  4. ryanofsky commented at 11:51 AM on June 3, 2021: member

    Seems to cause -Werror,-Wunreachable-code-loop-increment error https://cirrus-ci.com/task/5561194028204032?logs=ci#L2596

  5. MarcoFalke commented at 11:56 AM on June 3, 2021: member

    Seems to cause -Werror,-Wunreachable-code-loop-increment error https://cirrus-ci.com/task/5561194028204032?logs=ci#L2596

    Ah I remember this is why I removed the loop initially. Quite funny that a compiler warning encourages you to introduce a bug.

  6. MarcoFalke force-pushed on Jun 3, 2021
  7. MarcoFalke renamed this:
    util: Properly handle -noincludeconf on command line
    util: Properly handle -noincludeconf on command line (take 2)
    on Jun 3, 2021
  8. ryanofsky approved
  9. ryanofsky commented at 12:33 PM on June 3, 2021: member

    Code review ACK fa2fc70adefda51913b714993931e281a67de5e0. Fix looks good. I also worked on adding a test for this:

    diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
    index d463bcdd8e3..2df5c808fa2 100644
    --- a/src/test/util_tests.cpp
    +++ b/src/test/util_tests.cpp
    @@ -329,6 +329,27 @@ BOOST_FIXTURE_TEST_CASE(util_CheckValue, CheckValueTest)
         CheckValue(M::ALLOW_ANY, "-value=abc", Expect{"abc"}.String("abc").Int(0).Bool(false).List({"abc"}));
     }
     
    +class NoIncludeConfTest : public TestChain100Setup
    +{
    +public:
    +    std::string Parse(const char* arg)
    +    {
    +        TestArgsManager test;
    +        test.SetupArgs({{"-includeconf", ArgsManager::ALLOW_ANY}});
    +        const char* argv[] = {"ignored", arg};
    +        std::string error;
    +        bool success = test.ParseParameters(2, (char**)argv, error);
    +        return success ? "" : 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 27174a6028f..f9fc446e887 100644
    --- a/src/util/system.cpp
    +++ b/src/util/system.cpp
    @@ -367,9 +367,11 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
     
         // we do not allow -includeconf from command line
         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();
    -            return false; // pick first value as example
    +        util::SettingsSpan values{*includes};
    +        if (!values.empty()) {
    +            // pick first value as example
    +            error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write();
    +            return false;
             }
         }
         return true;
    
  10. MarcoFalke added the label Waiting for author on Jun 3, 2021
  11. MarcoFalke removed the label Waiting for author on Jun 4, 2021
  12. MarcoFalke force-pushed on Jun 4, 2021
  13. MarcoFalke commented at 9:06 AM on June 4, 2021: member

    Thanks for the unit test. Force pushed

  14. util: Properly handle -noincludeconf on command line
    This bug was introduced in commit
    fad0867d6ab9430070aa7d60bf7617a6508e0586.
    
    Unit test
    Co-Authored-By: Russell Yanofsky <russ@yanofsky.org>
    fa910b4765
  15. MarcoFalke force-pushed on Jun 4, 2021
  16. ryanofsky approved
  17. ryanofsky commented at 9:56 AM on June 4, 2021: member

    Code review ACK fa910b47656d0e69cccb1f31804f2b11aa45d053. Nice cleanups!

  18. practicalswift commented at 7:08 PM on June 6, 2021: contributor

    cr ACK fa910b47656d0e69cccb1f31804f2b11aa45d053: patch looks correct

  19. fanquake merged this on Jun 7, 2021
  20. fanquake closed this on Jun 7, 2021

  21. MarcoFalke deleted the branch on Jun 7, 2021
  22. sidhujag referenced this in commit 8af59699fe on Jun 9, 2021
  23. luke-jr referenced this in commit ccc9caf638 on Jun 29, 2021
  24. luke-jr referenced this in commit 0bbaa6b2d3 on Jun 29, 2021
  25. fanquake referenced this in commit da816247f0 on Jun 30, 2021
  26. stevenroose referenced this in commit bd2e2d5c64 on Jul 1, 2021
  27. fanquake referenced this in commit bd2f4164c6 on Jul 8, 2021
  28. gwillen referenced this in commit 1b79f721e2 on Jun 1, 2022
  29. DrahtBot locked this on Aug 18, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 18:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me