mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 18:45:52 +00:00
Avoid directly using memcpy to deserialize data
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
#include <ripple/overlay/predicates.h>
|
#include <ripple/overlay/predicates.h>
|
||||||
#include <ripple/protocol/digest.h>
|
#include <ripple/protocol/digest.h>
|
||||||
|
|
||||||
|
#include <boost/algorithm/clamp.hpp>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -1527,40 +1528,34 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMProposeSet> const& m)
|
|||||||
if (set.has_hops() && ! slot_->cluster())
|
if (set.has_hops() && ! slot_->cluster())
|
||||||
set.set_hops(set.hops() + 1);
|
set.set_hops(set.hops() + 1);
|
||||||
|
|
||||||
auto const type = publicKeyType(
|
auto const sig = makeSlice(set.signature());
|
||||||
makeSlice(set.nodepubkey()));
|
|
||||||
|
|
||||||
// VFALCO Magic numbers are bad
|
// Preliminary check for the validity of the signature: A DER encoded
|
||||||
// Roll this into a validation function
|
// signature can't be longer than 72 bytes.
|
||||||
if ((! type) ||
|
if ((boost::algorithm::clamp(sig.size(), 64, 72) != sig.size()) ||
|
||||||
(set.currenttxhash ().size () != 32) ||
|
(publicKeyType(makeSlice(set.nodepubkey())) != KeyType::secp256k1))
|
||||||
(set.signature ().size () < 56) ||
|
|
||||||
(set.signature ().size () > 128)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
JLOG(p_journal_.warn()) << "Proposal: malformed";
|
JLOG(p_journal_.warn()) << "Proposal: malformed";
|
||||||
fee_ = Resource::feeInvalidSignature;
|
fee_ = Resource::feeInvalidSignature;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set.previousledger ().size () != 32)
|
if (set.currenttxhash().size() != 32 || set.previousledger().size() != 32)
|
||||||
{
|
{
|
||||||
JLOG(p_journal_.warn()) << "Proposal: malformed";
|
JLOG(p_journal_.warn()) << "Proposal: malformed";
|
||||||
fee_ = Resource::feeInvalidRequest;
|
fee_ = Resource::feeInvalidRequest;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PublicKey const publicKey (makeSlice(set.nodepubkey()));
|
auto const proposeHash = uint256::fromVoid(set.currenttxhash().data());
|
||||||
|
auto const prevLedger = uint256::fromVoid(set.previousledger().data());
|
||||||
|
|
||||||
|
PublicKey const publicKey {makeSlice(set.nodepubkey())};
|
||||||
NetClock::time_point const closeTime { NetClock::duration{set.closetime()} };
|
NetClock::time_point const closeTime { NetClock::duration{set.closetime()} };
|
||||||
Slice signature (set.signature().data(), set.signature ().size());
|
|
||||||
|
|
||||||
uint256 proposeHash, prevLedger;
|
uint256 const suppression = proposalUniqueId (
|
||||||
memcpy (proposeHash.begin (), set.currenttxhash ().data (), 32);
|
|
||||||
memcpy (prevLedger.begin (), set.previousledger ().data (), 32);
|
|
||||||
|
|
||||||
uint256 suppression = proposalUniqueId (
|
|
||||||
proposeHash, prevLedger, set.proposeseq(),
|
proposeHash, prevLedger, set.proposeseq(),
|
||||||
closeTime, publicKey.slice(), signature);
|
closeTime, publicKey.slice(), sig);
|
||||||
|
|
||||||
if (! app_.getHashRouter ().addSuppressionPeer (suppression, id_))
|
if (! app_.getHashRouter ().addSuppressionPeer (suppression, id_))
|
||||||
{
|
{
|
||||||
@@ -1590,7 +1585,7 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMProposeSet> const& m)
|
|||||||
|
|
||||||
auto proposal = RCLCxPeerPos(
|
auto proposal = RCLCxPeerPos(
|
||||||
publicKey,
|
publicKey,
|
||||||
signature,
|
sig,
|
||||||
suppression,
|
suppression,
|
||||||
RCLCxPeerPos::Proposal{
|
RCLCxPeerPos::Proposal{
|
||||||
prevLedger,
|
prevLedger,
|
||||||
|
|||||||
Reference in New Issue
Block a user