Skip to content

Commit

Permalink
[FAB-5339] Add missing nil check to extensions.go
Browse files Browse the repository at this point in the history
There is a missing nil check, that might make the code
result in a null pointer panic.

For reference: IsDataMsg is:

func (m *GossipMessage) IsDataMsg() bool {
	return m.GetDataMsg() != nil
}

Change-Id: I5e20dee188e863b932312a7963f0ca73965c1457
Signed-off-by: yacovm <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Jul 17, 2017
1 parent 60926fd commit 3cde835
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion protos/gossip/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func (m *SignedGossipMessage) String() string {
var isSimpleMsg bool
if m.GetStateResponse() != nil {
gMsg = fmt.Sprintf("StateResponse with %d items", len(m.GetStateResponse().Payloads))
} else if m.IsDataMsg() {
} else if m.IsDataMsg() && m.GetDataMsg().Payload != nil {
gMsg = m.GetDataMsg().Payload.toString()
} else if m.IsDataUpdate() {
update := m.GetDataUpdate()
Expand Down
4 changes: 4 additions & 0 deletions protos/gossip/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func TestToString(t *testing.T) {
},
}
assert.NotContains(t, fmt.Sprintf("%v", sMsg), "2")
sMsg.GetDataMsg().Payload = nil
assert.NotPanics(t, func() {
_ = sMsg.String()
})

sMsg = &SignedGossipMessage{
GossipMessage: &GossipMessage{
Expand Down

0 comments on commit 3cde835

Please sign in to comment.