epee: when loading a JSON RPC payload, ensure params is an object

this makes it easier to spot those mistakes by the caller
This commit is contained in:
moneromooo-monero 2023-01-01 10:10:28 +00:00
parent 9367b432f6
commit b67e931843
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
1 changed files with 10 additions and 0 deletions

View File

@ -152,6 +152,16 @@
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
return true; \
} \
epee::serialization::storage_entry se; \
if(ps.get_value("params", se, nullptr) && se.type() != typeid(epee::serialization::section)) \
{ \
boost::value_initialized<epee::json_rpc::error_response> rsp; \
static_cast<epee::json_rpc::error_response&>(rsp).jsonrpc = "2.0"; \
static_cast<epee::json_rpc::error_response&>(rsp).error.code = -32701; \
static_cast<epee::json_rpc::error_response&>(rsp).error.message = "Params is not an object"; \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
return true; \
} \
epee::serialization::storage_entry id_; \
id_ = epee::serialization::storage_entry(std::string()); \
ps.get_value("id", id_, nullptr); \