Skip to content

Commit 3cde835

Browse files
committed
[FAB-5339] Add missing nil check to extensions.go
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 <[email protected]>
1 parent 60926fd commit 3cde835

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

protos/gossip/extensions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ func (m *SignedGossipMessage) String() string {
521521
var isSimpleMsg bool
522522
if m.GetStateResponse() != nil {
523523
gMsg = fmt.Sprintf("StateResponse with %d items", len(m.GetStateResponse().Payloads))
524-
} else if m.IsDataMsg() {
524+
} else if m.IsDataMsg() && m.GetDataMsg().Payload != nil {
525525
gMsg = m.GetDataMsg().Payload.toString()
526526
} else if m.IsDataUpdate() {
527527
update := m.GetDataUpdate()

protos/gossip/extensions_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func TestToString(t *testing.T) {
7272
},
7373
}
7474
assert.NotContains(t, fmt.Sprintf("%v", sMsg), "2")
75+
sMsg.GetDataMsg().Payload = nil
76+
assert.NotPanics(t, func() {
77+
_ = sMsg.String()
78+
})
7579

7680
sMsg = &SignedGossipMessage{
7781
GossipMessage: &GossipMessage{

0 commit comments

Comments
 (0)