Fix segfault + fix IndexError (causes also segfault in release)

This commit is contained in:
kdeme 2019-10-09 22:19:41 +02:00
parent 4cf3262902
commit 87f2a51a1b
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
1 changed files with 4 additions and 1 deletions

View File

@ -240,7 +240,10 @@ proc invokeThunk*(peer: Peer, msgId: int, msgData: var Rlp): Future[void] =
"RLPx message with an invalid id " & $msgId &
" on a connection supporting " & peer.dispatcher.describeProtocols)
if msgId >= peer.dispatcher.messages.len: invalidIdError()
# msgId can be negative as it has int as type and gets decoded from rlp
if msgId >= peer.dispatcher.messages.len or msgId < 0: invalidIdError()
if peer.dispatcher.messages[msgId].isNil: invalidIdError()
let thunk = peer.dispatcher.messages[msgId].thunk
if thunk == nil: invalidIdError()