Skip to content

Commit

Permalink
Force json commands to be objects
Browse files Browse the repository at this point in the history
* Null json values can be objects or arrays.
* json arrays are now interpreted as batch commands.
* json objects are single commands.
* null jsons are ambiguous as to whether they are single or batch
  commands and should be avoided.
  • Loading branch information
HowardHinnant authored and nbougalis committed Jan 10, 2018
1 parent e3499b5 commit 7ff6d34
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/ripple/net/impl/RPCCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ class RPCParser
if (reader.parse (jvParams[2u].asString (), txJSON))
{
// sign_for txJSON.
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

jvRequest[jss::account] = jvParams[0u].asString ();
jvRequest[jss::secret] = jvParams[1u].asString ();
Expand Down Expand Up @@ -802,7 +802,7 @@ class RPCParser
Json::Value parseRipplePathFind (Json::Value const& jvParams)
{
Json::Reader reader;
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};
bool bLedger = 2 == jvParams.size ();

JLOG (j_.trace()) << "RPC json: " << jvParams[0u];
Expand Down Expand Up @@ -835,7 +835,7 @@ class RPCParser
{
// Submitting tx_blob

Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

jvRequest[jss::tx_blob] = jvParams[0u].asString ();

Expand All @@ -845,7 +845,7 @@ class RPCParser
&& reader.parse (jvParams[1u].asString (), txJSON))
{
// Signing or submitting tx_json.
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

jvRequest[jss::secret] = jvParams[0u].asString ();
jvRequest[jss::tx_json] = txJSON;
Expand All @@ -870,7 +870,7 @@ class RPCParser
Json::Reader reader;
if (reader.parse (jvParams[0u].asString (), txJSON))
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};
jvRequest[jss::tx_json] = txJSON;
return jvRequest;
}
Expand All @@ -889,7 +889,7 @@ class RPCParser
if (txHash.length() != 64)
return rpcError (rpcINVALID_PARAMS);

Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};
jvRequest[jss::tx_hash] = txHash;

jvParseLedger (jvRequest, jvParams[1u].asString());
Expand All @@ -907,7 +907,7 @@ class RPCParser
// tx <transaction_id>
Json::Value parseTx (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

if (jvParams.size () > 1)
{
Expand All @@ -922,7 +922,7 @@ class RPCParser
// tx_history <index>
Json::Value parseTxHistory (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

jvRequest[jss::start] = jvParams[0u].asUInt ();

Expand All @@ -935,7 +935,7 @@ class RPCParser
// shell history file (e.g. .bash_history) and it may be leaked via the process status command (i.e. ps).
Json::Value parseValidationCreate (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

if (jvParams.size ())
jvRequest[jss::secret] = jvParams[0u].asString ();
Expand All @@ -949,7 +949,7 @@ class RPCParser
// shell history file (e.g. .bash_history) and it may be leaked via the process status command (i.e. ps).
Json::Value parseValidationSeed (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

if (jvParams.size ())
jvRequest[jss::secret] = jvParams[0u].asString ();
Expand All @@ -961,7 +961,7 @@ class RPCParser
// <passphrase> is only for testing. Master seeds should only be generated randomly.
Json::Value parseWalletPropose (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

if (jvParams.size ())
jvRequest[jss::passphrase] = jvParams[0u].asString ();
Expand All @@ -972,7 +972,7 @@ class RPCParser
// wallet_seed [<seed>|<passphrase>|<passkey>]
Json::Value parseWalletSeed (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

if (jvParams.size ())
jvRequest[jss::secret] = jvParams[0u].asString ();
Expand All @@ -988,7 +988,7 @@ class RPCParser
unsigned int index = 0;
const unsigned int size = jvParams.size ();

Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

std::string param = jvParams[index++].asString ();
if (param.empty ())
Expand Down
15 changes: 15 additions & 0 deletions src/test/rpc/ValidatorRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,27 @@ class ValidatorRPC_test : public beast::unit_test::suite
}
}

void
test_validation_create()
{
using namespace test::jtx;
Env env{*this};
auto result = env.rpc("validation_create");
BEAST_EXPECT(result.isMember(jss::result) &&
result[jss::result][jss::status] == "success");
result = env.rpc("validation_create",
"BAWL MAN JADE MOON DOVE GEM SON NOW HAD ADEN GLOW TIRE");
BEAST_EXPECT(result.isMember(jss::result) &&
result[jss::result][jss::status] == "success");
}

void
run()
{
testPrivileges();
testStaticUNL();
testDynamicUNL();
test_validation_create();
}
};

Expand Down

0 comments on commit 7ff6d34

Please sign in to comment.