aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/server.cpp
diff options
context:
space:
mode:
authorJoão Barbosa <joao@uphold.com>2016-03-30 00:59:29 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2016-04-15 14:55:52 +0200
commit41e835dd50d358c127bab17a1f2872471dbdfe9c (patch)
tree264580e003adcc38decf0ad0e8f0f1c8634431eb /src/rpc/server.cpp
parenta4ca44d2766ab0e5f67f7b24bfa95ed0b80c7322 (diff)
Add strict flag to RPCTypeCheckObj
Strict flag forces type check on all object keys.
Diffstat (limited to 'src/rpc/server.cpp')
-rw-r--r--src/rpc/server.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp
index 8326fe14d2..d06a9142b6 100644
--- a/src/rpc/server.cpp
+++ b/src/rpc/server.cpp
@@ -89,7 +89,8 @@ void RPCTypeCheck(const UniValue& params,
void RPCTypeCheckObj(const UniValue& o,
const map<string, UniValue::VType>& typesExpected,
- bool fAllowNull)
+ bool fAllowNull,
+ bool fStrict)
{
BOOST_FOREACH(const PAIRTYPE(string, UniValue::VType)& t, typesExpected)
{
@@ -104,6 +105,18 @@ void RPCTypeCheckObj(const UniValue& o,
throw JSONRPCError(RPC_TYPE_ERROR, err);
}
}
+
+ if (fStrict)
+ {
+ BOOST_FOREACH(const string& k, o.getKeys())
+ {
+ if (typesExpected.count(k) == 0)
+ {
+ string err = strprintf("Unexpected key %s", k);
+ throw JSONRPCError(RPC_TYPE_ERROR, err);
+ }
+ }
+ }
}
CAmount AmountFromValue(const UniValue& value)