Skip to content

Commit

Permalink
core: add remaining nil checks (#2338)
Browse files Browse the repository at this point in the history
Add remaining nil checks that were missing as part of OBOL-03.

category: misc
ticket: #1997
  • Loading branch information
dB2510 committed Jun 20, 2023
1 parent 64ab966 commit d9ce91e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/consensus/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (

// newMsg returns a new msg.
func newMsg(pbMsg *pbv1.QBFTMsg, justification []*pbv1.QBFTMsg, values map[[32]byte]*anypb.Any) (msg, error) {
if pbMsg == nil {
return msg{}, errors.New("nil qbft message")
}

// Do all possible error conversions first.
var (
valueHash [32]byte
Expand Down
6 changes: 5 additions & 1 deletion core/priority/prioritiser.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func newInternal(tcpNode host.Host, peers []peer.ID, minRequired int,
func() proto.Message { return new(pbv1.PriorityMsg) },
func(ctx context.Context, pID peer.ID, msg proto.Message) (proto.Message, bool, error) {
prioMsg, ok := msg.(*pbv1.PriorityMsg)
if !ok {
if !ok || prioMsg == nil {
return nil, false, errors.New("invalid priority message")
}

Expand Down Expand Up @@ -200,6 +200,10 @@ func (p *Prioritiser) Prioritise(ctx context.Context, msg *pbv1.PriorityMsg) err

// handleRequest handles a priority message exchange initiated by a peer.
func (p *Prioritiser) handleRequest(ctx context.Context, pID peer.ID, msg *pbv1.PriorityMsg) (*pbv1.PriorityMsg, error) {
if msg == nil {
return nil, errors.New("nil priority message")
}

if pID.String() != msg.PeerId {
return nil, errors.New("invalid priority message peer id", z.Str("expect", pID.String()), z.Str("actual", msg.PeerId))
} else if err := p.msgValidator(msg); err != nil {
Expand Down

0 comments on commit d9ce91e

Please sign in to comment.