rpc: Actually throw help when passed invalid number of params #15401

pull MarcoFalke wants to merge 2 commits into bitcoin:master from MarcoFalke:Mf1902-rpcNumArgs changing 5 files +46 −22
  1. MarcoFalke commented at 9:48 PM on February 13, 2019: member

    Can be tested by

    • running the included test against an old binary (compiled without this patch)
    • calling setban 1 "add" 3 4 5 6 7 8 9 0 in the gui
  2. MarcoFalke added the label RPC/REST/ZMQ on Feb 13, 2019
  3. MarcoFalke added this to the milestone 0.18.0 on Feb 18, 2019
  4. in src/rpc/util.cpp:294 in fa910b02d9 outdated
     286 | @@ -287,6 +287,16 @@ std::string RPCExamples::ToDescriptionString() const
     287 |      return m_examples.empty() ? m_examples : "\nExamples:\n" + m_examples;
     288 |  }
     289 |  
     290 | +bool RPCHelpMan::IsValidNumArgs(size_t num_args) const
     291 | +{
     292 | +    size_t num_required_args = 0;
     293 | +    for (size_t i = 0; i < m_args.size();) {
     294 | +        if (!m_args.at(i++).IsOptional()) {
    


    promag commented at 4:44 PM on February 20, 2019:

    👀


    promag commented at 5:10 PM on February 20, 2019:

    Could reverse the loop and break on first optional?


    MarcoFalke commented at 6:36 PM on February 20, 2019:

    Done

  5. promag commented at 5:09 PM on February 20, 2019: member

    Tested with master binary and functional test fails.

  6. rpc: Add RPCHelpMan::IsValidNumArgs() fa05626ca7
  7. rpc: Actually throw help when passed invalid number of params fa4ce7038d
  8. MarcoFalke force-pushed on Feb 20, 2019
  9. in src/rpc/util.cpp:327 in fa4ce7038d
     322 | +        if (!m_args.at(n - 1).IsOptional()) {
     323 | +            num_required_args = n;
     324 | +            break;
     325 | +        }
     326 | +    }
     327 | +    return num_required_args <= num_args && num_args <= m_args.size();
    


    promag commented at 9:46 PM on February 20, 2019:

    nit, could early return with if (num_args > m_args.size()) return false;.


    MarcoFalke commented at 10:03 PM on February 20, 2019:

    I think this is the wrong place to overoptimize

  10. in src/rpc/util.cpp:321 in fa4ce7038d
     314 | @@ -315,6 +315,17 @@ std::string RPCExamples::ToDescriptionString() const
     315 |      return m_examples.empty() ? m_examples : "\nExamples:\n" + m_examples;
     316 |  }
     317 |  
     318 | +bool RPCHelpMan::IsValidNumArgs(size_t num_args) const
     319 | +{
     320 | +    size_t num_required_args = 0;
     321 | +    for (size_t n = m_args.size(); n > 0; --n) {
    


    promag commented at 9:47 PM on February 20, 2019:

    nit, could change condition to n > num_args?


    MarcoFalke commented at 10:02 PM on February 20, 2019:

    No, that would be incorrect

  11. promag commented at 9:51 PM on February 20, 2019: member

    Tested ACK fa4ce7038d444defe0b98a30097174c278054a33.

    Could update license year in test/functional/rpc_getblockstats.py.

  12. laanwj commented at 7:59 AM on February 25, 2019: member

    Could update license year in test/functional/rpc_getblockstats.py.

    Please, let's not start nitting about copyright years. In as far as they matter at all (we don't know!) updating these once per year is enough.

  13. laanwj commented at 8:24 AM on February 25, 2019: member

    utACK fa4ce7038d444defe0b98a30097174c278054a33

  14. laanwj merged this on Feb 25, 2019
  15. laanwj closed this on Feb 25, 2019

  16. laanwj referenced this in commit 1a8a5ede9f on Feb 25, 2019
  17. MarcoFalke deleted the branch on Feb 25, 2019
  18. deadalnix referenced this in commit a299d8aa29 on May 22, 2020
  19. kittywhiskers referenced this in commit f03a84d917 on Dec 12, 2021
  20. kittywhiskers referenced this in commit 2fecd1495f on Dec 12, 2021
  21. DrahtBot locked this on Dec 16, 2021

Milestone
0.18.0


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 15:15 UTC

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