mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
rpc: Check default value type againts argument type
This commit is contained in:
parent
f81ef4303e
commit
bee56c78e9
1 changed files with 27 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue