diff options
author | João Barbosa <joao.paulo.barbosa@gmail.com> | 2021-04-15 11:07:47 +0100 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2021-04-17 00:22:53 +0100 |
commit | bee56c78e94417f89b1f48682404e2821b57bdec (patch) | |
tree | 05c0961be6531821a32f2a7b4472e22451c9bc75 /src | |
parent | f81ef4303e057e85aa24772c865287c17ffa4350 (diff) | |
download | bitcoin-bee56c78e94417f89b1f48682404e2821b57bdec.tar.xz |
rpc: Check default value type againts argument type
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/util.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 71c6160322..df3ee9f007 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -498,6 +498,33 @@ RPCHelpMan::RPCHelpMan(std::string name, std::string description, std::vector<RP for (const std::string& name : names) { CHECK_NONFATAL(named_args.insert(name).second); } + // Default value type should match argument type only when defined + if (arg.m_fallback.index() == 2) { + const RPCArg::Type type = arg.m_type; + switch (std::get<RPCArg::Default>(arg.m_fallback).getType()) { + case UniValue::VOBJ: + CHECK_NONFATAL(type == RPCArg::Type::OBJ); + break; + case UniValue::VARR: + CHECK_NONFATAL(type == RPCArg::Type::ARR); + break; + case UniValue::VSTR: + CHECK_NONFATAL(type == RPCArg::Type::STR || type == RPCArg::Type::STR_HEX || type == RPCArg::Type::AMOUNT); + break; + case UniValue::VNUM: + CHECK_NONFATAL(type == RPCArg::Type::NUM || type == RPCArg::Type::AMOUNT || type == RPCArg::Type::RANGE); + break; + case UniValue::VBOOL: + CHECK_NONFATAL(type == RPCArg::Type::BOOL); + break; + case UniValue::VNULL: + // Null values are accepted in all arguments + break; + default: + CHECK_NONFATAL(false); + break; + } + } } } |