rpc: Check default value type againts argument type

pull/826/head
João Barbosa 4 years ago
parent f81ef4303e
commit bee56c78e9

@ -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…
Cancel
Save