Skip to content

Commit bee56c7

Browse files
committed
rpc: Check default value type againts argument type
1 parent f81ef43 commit bee56c7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/rpc/util.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,33 @@ RPCHelpMan::RPCHelpMan(std::string name, std::string description, std::vector<RP
498498
for (const std::string& name : names) {
499499
CHECK_NONFATAL(named_args.insert(name).second);
500500
}
501+
// Default value type should match argument type only when defined
502+
if (arg.m_fallback.index() == 2) {
503+
const RPCArg::Type type = arg.m_type;
504+
switch (std::get<RPCArg::Default>(arg.m_fallback).getType()) {
505+
case UniValue::VOBJ:
506+
CHECK_NONFATAL(type == RPCArg::Type::OBJ);
507+
break;
508+
case UniValue::VARR:
509+
CHECK_NONFATAL(type == RPCArg::Type::ARR);
510+
break;
511+
case UniValue::VSTR:
512+
CHECK_NONFATAL(type == RPCArg::Type::STR || type == RPCArg::Type::STR_HEX || type == RPCArg::Type::AMOUNT);
513+
break;
514+
case UniValue::VNUM:
515+
CHECK_NONFATAL(type == RPCArg::Type::NUM || type == RPCArg::Type::AMOUNT || type == RPCArg::Type::RANGE);
516+
break;
517+
case UniValue::VBOOL:
518+
CHECK_NONFATAL(type == RPCArg::Type::BOOL);
519+
break;
520+
case UniValue::VNULL:
521+
// Null values are accepted in all arguments
522+
break;
523+
default:
524+
CHECK_NONFATAL(false);
525+
break;
526+
}
527+
}
501528
}
502529
}
503530

0 commit comments

Comments
 (0)