check validator to avoid nil pointer access

Signed-off-by: Leo Chen <leo@harmony.one>
pull/465/head
Leo Chen 6 years ago
parent d682064202
commit 214ff491e0
  1. 10
      consensus/consensus_leader.go

@ -147,6 +147,11 @@ func (consensus *Consensus) processPrepareMessage(message consensus_proto.Messag
validatorPeer := consensus.getValidatorPeerByID(validatorID) validatorPeer := consensus.getValidatorPeerByID(validatorID)
if validatorPeer == nil {
utils.GetLogInstance().Error("Invalid validator", "validatorID", validatorID)
return
}
if err := consensus.checkConsensusMessage(message, validatorPeer.PubKey); err != nil { if err := consensus.checkConsensusMessage(message, validatorPeer.PubKey); err != nil {
utils.GetLogInstance().Debug("Failed to check the validator message", "validatorID", validatorID) utils.GetLogInstance().Debug("Failed to check the validator message", "validatorID", validatorID)
return return
@ -214,6 +219,11 @@ func (consensus *Consensus) processCommitMessage(message consensus_proto.Message
validatorPeer := consensus.getValidatorPeerByID(validatorID) validatorPeer := consensus.getValidatorPeerByID(validatorID)
if validatorPeer == nil {
utils.GetLogInstance().Error("Invalid validator", "validatorID", validatorID)
return
}
if err := consensus.checkConsensusMessage(message, validatorPeer.PubKey); err != nil { if err := consensus.checkConsensusMessage(message, validatorPeer.PubKey); err != nil {
utils.GetLogInstance().Debug("Failed to check the validator message", "validatorID", validatorID) utils.GetLogInstance().Debug("Failed to check the validator message", "validatorID", validatorID)
return return

Loading…
Cancel
Save