Add message length check to prevent index out of bound issue

pull/166/head
Rongjian Lan 6 years ago
parent a581053084
commit da48957bea
  1. 8
      consensus/consensus_leader.go
  2. 8
      consensus/consensus_validator.go

@ -166,6 +166,10 @@ func (consensus *Consensus) commitByLeader(firstRound bool) {
// processCommitMessage processes the commit message sent from validators // processCommitMessage processes the commit message sent from validators
func (consensus *Consensus) processCommitMessage(payload []byte, targetState State) { func (consensus *Consensus) processCommitMessage(payload []byte, targetState State) {
if len(payload) < 4+32+2+32+64 {
consensus.Log.Debug("Received malformed message %x", payload)
return
}
// Read payload data // Read payload data
offset := 0 offset := 0
// 4 byte consensus id // 4 byte consensus id
@ -297,6 +301,10 @@ func (consensus *Consensus) responseByLeader(challenge kyber.Scalar, firstRound
// Processes the response message sent from validators // Processes the response message sent from validators
func (consensus *Consensus) processResponseMessage(payload []byte, targetState State) { func (consensus *Consensus) processResponseMessage(payload []byte, targetState State) {
if len(payload) < 4+32+2+32+64 {
consensus.Log.Debug("Received malformed message %x", payload)
return
}
//#### Read payload data //#### Read payload data
offset := 0 offset := 0
// 4 byte consensus id // 4 byte consensus id

@ -131,6 +131,10 @@ func (consensus *Consensus) processAnnounceMessage(payload []byte) {
// Processes the challenge message sent from the leader // Processes the challenge message sent from the leader
func (consensus *Consensus) processChallengeMessage(payload []byte, targetState State) { func (consensus *Consensus) processChallengeMessage(payload []byte, targetState State) {
if len(payload) < 4+32+2+33+33+32+64 {
consensus.Log.Debug("Received malformed message %x", payload)
return
}
//#### Read payload data //#### Read payload data
offset := 0 offset := 0
// 4 byte consensus id // 4 byte consensus id
@ -276,6 +280,10 @@ func (consensus *Consensus) processChallengeMessage(payload []byte, targetState
// Processes the collective signature message sent from the leader // Processes the collective signature message sent from the leader
func (consensus *Consensus) processCollectiveSigMessage(payload []byte) { func (consensus *Consensus) processCollectiveSigMessage(payload []byte) {
if len(payload) < 4+32+2+64+64 {
consensus.Log.Debug("Received malformed message %x", payload)
return
}
//#### Read payload data //#### Read payload data
offset := 0 offset := 0
// 4 byte consensus id // 4 byte consensus id

Loading…
Cancel
Save