Clean local transaction checks. Check account field size

This commit is contained in:
David Schwartz
2014-03-25 14:52:29 -07:00
parent be9e18ddb8
commit 1e54472a1d
5 changed files with 44 additions and 5 deletions

View File

@@ -765,7 +765,7 @@ void NetworkOPsImp::submitTransaction (Job&, SerializedTransaction::pointer iTra
{
try
{
if (!isMemoOkay (*trans) || !trans->checkSign ())
if (!passesLocalChecks (*trans) || !trans->checkSign ())
{
m_journal.warning << "Submitted transaction has bad signature";
getApp().getHashRouter ().setFlag (suppress, SF_BAD);

View File

@@ -313,6 +313,7 @@ std::string SerializedTransaction::getMetaSQL (Serializer rawTxn, std::uint32_t
}
//------------------------------------------------------------------------------
bool isMemoOkay (STObject const& st)
{
if (!st.isFieldPresent (sfMemos))
@@ -327,6 +328,42 @@ bool isMemoOkay (STObject const& st)
return true;
}
// Ensure all account fields are 160-bits
bool isAccountFieldOkay (STObject const& st)
{
for (int i = 0; i < st.getCount(); ++i)
{
const STAccount* t = dynamic_cast<STAccount const*>(st.peekAtPIndex (i));
if (t&& !t->isValueH160 ())
return false;
}
return true;
}
bool passesLocalChecks (STObject const& st, std::string& reason)
{
if (!isMemoOkay (st))
{
reason = "The memo exceeds the maximum allowed size.";
return false;
}
if (!isAccountFieldOkay (st))
{
reason = "An account field is invalid.";
return false;
}
return true;
}
bool passesLocalChecks (STObject const& st)
{
std::string reason;
return passesLocalChecks (st, reason);
}
//------------------------------------------------------------------------------
class SerializedTransaction_test : public beast::unit_test::suite

View File

@@ -153,7 +153,8 @@ private:
mutable bool mSigBad;
};
bool isMemoOkay (STObject const& st);
bool passesLocalChecks (STObject const& st, std::string&);
bool passesLocalChecks (STObject const& st);
} // ripple

View File

@@ -442,10 +442,11 @@ Json::Value RPCHandler::transactionSign (Json::Value params,
"Exception occurred during transaction");
}
if (!isMemoOkay (*stpTrans))
std::string reason;
if (!passesLocalChecks (*stpTrans, reason))
{
return RPC::make_error (rpcINVALID_PARAMS,
"The memo exceeds the maximum allowed size.");
reason);
}
if (params.isMember ("debug_signing"))

View File

@@ -33,7 +33,7 @@ Transaction::Transaction (SerializedTransaction::ref sit, bool bValidate)
return;
}
if (!bValidate || (isMemoOkay (*mTransaction) && checkSign ()))
if (!bValidate || (passesLocalChecks (*mTransaction) && checkSign ()))
mStatus = NEW;
}