Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix segfault during sync bug
Segfault is occurring when a peer reconnects while its disconnect is
still pending, which results in a live Session but no entry in
EthereumCapability::m_peers.
EthereumCapability::interpretCapabilityPacket directly accesses m_peers
via node ID rather than using a lookup function, which is causing the
segfault.
  • Loading branch information
halfalicious committed Nov 20, 2019
commit 8f3052786ad28e4c730f6a6348e4e90db8ac0aa2
16 changes: 8 additions & 8 deletions libethereum/EthereumCapability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ void EthereumCapability::onDisconnect(NodeID const& _peerID)
bool EthereumCapability::interpretCapabilityPacket(
NodeID const& _peerID, unsigned _id, RLP const& _r)
{
auto& peer = m_peers[_peerID];
peer.setLastAsk(std::chrono::system_clock::to_time_t(chrono::system_clock::now()));
auto& remotePeer = peer(_peerID);
remotePeer.setLastAsk(std::chrono::system_clock::to_time_t(chrono::system_clock::now()));

try
{
Expand All @@ -648,10 +648,10 @@ bool EthereumCapability::interpretCapabilityPacket(
<< networkId << " / " << genesisHash << ", TD: " << totalDifficulty
<< " = " << latestHash;

peer.setStatus(
remotePeer.setStatus(
peerProtocolVersion, networkId, totalDifficulty, latestHash, genesisHash);
setIdle(_peerID);
m_peerObserver->onPeerStatus(peer);
m_peerObserver->onPeerStatus(remotePeer);
break;
}
case TransactionsPacket:
Expand Down Expand Up @@ -691,7 +691,7 @@ bool EthereumCapability::interpretCapabilityPacket(
}
case BlockHeadersPacket:
{
if (peer.asking() != Asking::BlockHeaders)
if (remotePeer.asking() != Asking::BlockHeaders)
LOG(m_loggerImpolite) << "Peer " << _peerID
<< " giving us block headers when we didn't ask for them.";
else
Expand Down Expand Up @@ -724,7 +724,7 @@ bool EthereumCapability::interpretCapabilityPacket(
}
case BlockBodiesPacket:
{
if (peer.asking() != Asking::BlockBodies)
if (remotePeer.asking() != Asking::BlockBodies)
LOG(m_loggerImpolite)
<< "Peer " << _peerID << " giving us block bodies when we didn't ask for them.";
else
Expand Down Expand Up @@ -803,7 +803,7 @@ bool EthereumCapability::interpretCapabilityPacket(
}
case NodeDataPacket:
{
if (peer.asking() != Asking::NodeData)
if (remotePeer.asking() != Asking::NodeData)
LOG(m_loggerImpolite)
<< "Peer " << _peerID << " giving us node data when we didn't ask for them.";
else
Expand All @@ -815,7 +815,7 @@ bool EthereumCapability::interpretCapabilityPacket(
}
case ReceiptsPacket:
{
if (peer.asking() != Asking::Receipts)
if (remotePeer.asking() != Asking::Receipts)
LOG(m_loggerImpolite)
<< "Peer " << _peerID << " giving us receipts when we didn't ask for them.";
else
Expand Down
2 changes: 1 addition & 1 deletion libethereum/EthereumPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace eth
class EthereumPeer
{
public:
EthereumPeer() = default;
EthereumPeer() = delete;
EthereumPeer(std::shared_ptr<p2p::CapabilityHostFace> _host, NodeID const& _peerID,
u256 const& /*_capabilityVersion*/)
: m_host(std::move(_host)), m_id(_peerID)
Expand Down