From 7178eabbf15fe1c3a86a75d3a9b4c96ae4e54a33 Mon Sep 17 00:00:00 2001 From: Ganesha Upadhyaya Date: Tue, 7 Apr 2020 23:30:35 -0700 Subject: [PATCH] rejecting malformed messages before processing (#2776) handling malformed messages locally minor --- consensus/checks.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/consensus/checks.go b/consensus/checks.go index aa8400ddf..e65c90425 100644 --- a/consensus/checks.go +++ b/consensus/checks.go @@ -11,6 +11,10 @@ import ( const MaxBlockNumDiff = 100 func (consensus *Consensus) validatorSanityChecks(msg *msg_pb.Message) bool { + if msg.GetConsensus() == nil { + consensus.getLogger().Warn().Msg("[validatorSanityChecks] malformed message") + return false + } consensus.getLogger().Debug(). Uint64("blockNum", msg.GetConsensus().BlockNum). Uint64("viewID", msg.GetConsensus().ViewId). @@ -47,6 +51,10 @@ func (consensus *Consensus) validatorSanityChecks(msg *msg_pb.Message) bool { } func (consensus *Consensus) leaderSanityChecks(msg *msg_pb.Message) bool { + if msg.GetConsensus() == nil { + consensus.getLogger().Warn().Msg("[leaderSanityChecks] malformed message") + return false + } consensus.getLogger().Debug(). Uint64("blockNum", msg.GetConsensus().BlockNum). Uint64("viewID", msg.GetConsensus().ViewId). @@ -180,6 +188,10 @@ func (consensus *Consensus) onPreparedSanityChecks( } func (consensus *Consensus) viewChangeSanityCheck(msg *msg_pb.Message) bool { + if msg.GetViewchange() == nil { + consensus.getLogger().Warn().Msg("[viewChangeSanityCheck] malformed message") + return false + } consensus.getLogger().Debug(). Msg("[viewChangeSanityCheck] Checking new message") senderKey, err := consensus.verifyViewChangeSenderKey(msg)