From a201a91ab0cc8e7f5d11b4668fd9b7f5248f8919 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 22 Dec 2012 16:25:42 -0800 Subject: [PATCH] Make RPC submit more robust. --- src/cpp/ripple/RPCHandler.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index c7a999a25..000ae1235 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -868,6 +868,10 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest) RippleAddress naSeed; RippleAddress raSrcAddressID; + cLog(lsDEBUG) + << boost::str(boost::format("doSubmit: %s") + % jvRequest); + if (!jvRequest.isMember("secret") || !jvRequest.isMember("tx_json")) { return rpcError(rpcINVALID_PARAMS); @@ -875,6 +879,10 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest) Json::Value txJSON = jvRequest["tx_json"]; + if (!txJSON.isObject()) + { + return rpcError(rpcINVALID_PARAMS); + } if (!naSeed.setSeedGeneric(jvRequest["secret"].asString())) { return rpcError(rpcBAD_SEED); @@ -887,18 +895,14 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest) { return rpcError(rpcSRC_ACT_MALFORMED); } + if (!txJSON.isMember("TransactionType")) + { + return rpcError(rpcINVALID_PARAMS); + } AccountState::pointer asSrc = mNetOps->getAccountState(mNetOps->getCurrentLedger(), raSrcAddressID); if (!asSrc) return rpcError(rpcSRC_ACT_MALFORMED); - if (!txJSON.isMember("Fee") - && ("OfferCreate" == txJSON["TransactionType"].asString() - || "OfferCancel" == txJSON["TransactionType"].asString() - || "TrustSet" == txJSON["TransactionType"].asString())) - { - txJSON["Fee"] = (int) theConfig.FEE_DEFAULT; - } - if ("Payment" == txJSON["TransactionType"].asString()) { @@ -976,8 +980,16 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest) } } - if (!txJSON.isMember("Sequence")) txJSON["Sequence"]=asSrc->getSeq(); - if (!txJSON.isMember("Flags")) txJSON["Flags"]=0; + if (!txJSON.isMember("Fee") + && ("OfferCreate" == txJSON["TransactionType"].asString() + || "OfferCancel" == txJSON["TransactionType"].asString() + || "TrustSet" == txJSON["TransactionType"].asString())) + { + txJSON["Fee"] = (int) theConfig.FEE_DEFAULT; + } + + if (!txJSON.isMember("Sequence")) txJSON["Sequence"] = asSrc->getSeq(); + if (!txJSON.isMember("Flags")) txJSON["Flags"] = 0; Ledger::pointer lpCurrent = mNetOps->getCurrentLedger(); SLE::pointer sleAccountRoot = mNetOps->getSLE(lpCurrent, Ledger::getAccountRootIndex(raSrcAddressID.getAccountID())); @@ -991,7 +1003,6 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest) bool bHaveAuthKey = false; RippleAddress naAuthorizedPublic; - RippleAddress naSecret = RippleAddress::createSeedGeneric(jvRequest["secret"].asString()); RippleAddress naMasterGenerator = RippleAddress::createGeneratorPublic(naSecret);