mirror of
https://github.com/status-im/nim-eth.git
synced 2025-02-17 16:37:15 +00:00
Fix possible AssertionError in ByteRange due to invalid access
This commit is contained in:
parent
903b72a5c8
commit
9ee208876d
@ -460,10 +460,14 @@ proc waitSingleMsg(peer: Peer, MsgType: type): Future[MsgType] {.async.} =
|
|||||||
"Invalid RLPx message body")
|
"Invalid RLPx message body")
|
||||||
|
|
||||||
elif nextMsgId == 1: # p2p.disconnect
|
elif nextMsgId == 1: # p2p.disconnect
|
||||||
let reason = DisconnectionReason nextMsgData.listElem(0).toInt(uint32)
|
if nextMsgData.isList():
|
||||||
await peer.disconnect(reason)
|
let reason = DisconnectionReason nextMsgData.listElem(0).toInt(uint32)
|
||||||
trace "disconnect message received in waitSingleMsg", reason, peer
|
await peer.disconnect(reason)
|
||||||
raisePeerDisconnected("Unexpected disconnect", reason)
|
trace "disconnect message received in waitSingleMsg", reason, peer
|
||||||
|
raisePeerDisconnected("Unexpected disconnect", reason)
|
||||||
|
else:
|
||||||
|
raise newException(RlpTypeMismatch,
|
||||||
|
"List expected, but the source RLP is not a list.")
|
||||||
else:
|
else:
|
||||||
warn "Dropped RLPX message",
|
warn "Dropped RLPX message",
|
||||||
msg = peer.dispatcher.messages[nextMsgId].name
|
msg = peer.dispatcher.messages[nextMsgId].name
|
||||||
@ -515,11 +519,17 @@ proc dispatchMessages*(peer: Peer) {.async.} =
|
|||||||
except PeerDisconnected:
|
except PeerDisconnected:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# TODO: is there a reason why we don't just allow `sendDisconnectMsg`
|
||||||
|
# to do its work here, with the usual thunk checks included?
|
||||||
if msgId == 1: # p2p.disconnect
|
if msgId == 1: # p2p.disconnect
|
||||||
let reason = msgData.listElem(0).toInt(uint32).DisconnectionReason
|
if msgData.isList():
|
||||||
trace "disconnect message received in dispatchMessages", reason, peer
|
let reason = msgData.listElem(0).toInt(uint32).DisconnectionReason
|
||||||
await peer.disconnect(reason, false)
|
trace "disconnect message received in dispatchMessages", reason, peer
|
||||||
break
|
await peer.disconnect(reason, false)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
debug "disconnect message with invalid rlp list", peer
|
||||||
|
await peer.disconnect(BreachOfProtocol, true)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await peer.invokeThunk(msgId, msgData)
|
await peer.invokeThunk(msgId, msgData)
|
||||||
@ -784,7 +794,9 @@ p2pProtocol devp2p(version = 0, rlpxName = "p2p"):
|
|||||||
listenPort: uint,
|
listenPort: uint,
|
||||||
nodeId: array[RawPublicKeySize, byte])
|
nodeId: array[RawPublicKeySize, byte])
|
||||||
|
|
||||||
proc sendDisconnectMsg(peer: Peer, reason: DisconnectionReason)
|
proc sendDisconnectMsg(peer: Peer, reason: DisconnectionReason) =
|
||||||
|
trace "disconnect message received", reason, peer
|
||||||
|
await peer.disconnect(reason, false)
|
||||||
|
|
||||||
# Adding an empty RLP list as the spec defines.
|
# Adding an empty RLP list as the spec defines.
|
||||||
# The parity client specifically checks if there is rlp data.
|
# The parity client specifically checks if there is rlp data.
|
||||||
|
@ -272,6 +272,7 @@ iterator items*(self: var Rlp): var Rlp =
|
|||||||
position = elemEnd
|
position = elemEnd
|
||||||
|
|
||||||
proc listElem*(self: Rlp, i: int): Rlp =
|
proc listElem*(self: Rlp, i: int): Rlp =
|
||||||
|
doAssert isList()
|
||||||
let
|
let
|
||||||
payloadOffset = payloadOffset()
|
payloadOffset = payloadOffset()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user