diff --git a/src/test/rpc/RPCCall_test.cpp b/src/test/rpc/RPCCall_test.cpp index f17d87884a..c9c1ad548a 100644 --- a/src/test/rpc/RPCCall_test.cpp +++ b/src/test/rpc/RPCCall_test.cpp @@ -1948,8 +1948,16 @@ static RPCCallTestData const rpcCallTestArray[] = { "can_delete", "4294967296", }, - RPCCallTestData::bad_cast, - R"()"}, + RPCCallTestData::no_exception, + R"({ + "method" : "can_delete", + "params" : [ + { + "error" : "invalidParams", + "error_message" : "Invalid field 'can_delete'." + } + ] +})"}, {// Note: this really shouldn't throw since it's a legitimate ledger hash. "can_delete: ledger hash with no alphas.", __LINE__, @@ -1957,8 +1965,16 @@ static RPCCallTestData const rpcCallTestArray[] = { "can_delete", "0123456701234567012345670123456701234567012345670123456701234567", }, - RPCCallTestData::bad_cast, - R"()"}, + RPCCallTestData::no_exception, + R"({ + "method" : "can_delete", + "params" : [ + { + "error" : "invalidParams", + "error_message" : "Invalid field 'can_delete'." + } + ] +})"}, // channel_authorize // ----------------------------------------------------------- diff --git a/src/xrpld/rpc/detail/RPCCall.cpp b/src/xrpld/rpc/detail/RPCCall.cpp index 8ca2548aea..ca8af78950 100644 --- a/src/xrpld/rpc/detail/RPCCall.cpp +++ b/src/xrpld/rpc/detail/RPCCall.cpp @@ -135,7 +135,7 @@ private: } } - static std::optional + static std::optional jvParseInt(Json::Value const& param) { if (param.isUInt() || param.isInt()) @@ -151,6 +151,22 @@ private: return std::nullopt; } + static std::optional + jvParseUInt(Json::Value const& param) + { + if (param.isUInt() || (param.isInt() && param.asInt() >= 0)) + return param.asUInt(); + + if (param.isString()) + { + std::uint32_t v; + if (beast::lexicalCastChecked(v, param.asString())) + return v; + } + + return std::nullopt; + } + static bool validPublicKey( std::string const& strPk, @@ -418,7 +434,12 @@ private: std::string input = jvParams[0u].asString(); if (input.find_first_not_of("0123456789") == std::string::npos) - jvRequest["can_delete"] = jvParams[0u].asUInt(); + { + if (auto seq = jvParseUInt(jvParams[0u])) + jvRequest["can_delete"] = *seq; + else + return RPC::invalid_field_error(jss::can_delete); + } else jvRequest["can_delete"] = input;