Skip to content

Commit 04ffb5c

Browse files
committed
[FAB-3955] Event producer registers nil handlers
This CR fixes a bug where the event producer would allow a nil handler to be registered. This resulted in a panic whenever the handler was used to send an event message. Change-Id: I757945a71a73b3f9a210ca25e1be1e4027ae2fdd Signed-off-by: Will Lahti <[email protected]>
1 parent 8629463 commit 04ffb5c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

events/producer/events.go

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ type chaincodeHandlerList struct {
5050
}
5151

5252
func (hl *chaincodeHandlerList) add(ie *pb.Interest, h *handler) (bool, error) {
53+
if h == nil {
54+
return false, fmt.Errorf("cannot add nil chaincode handler")
55+
}
56+
5357
hl.Lock()
5458
defer hl.Unlock()
5559

@@ -157,6 +161,9 @@ func (hl *chaincodeHandlerList) foreach(e *pb.Event, action func(h *handler)) {
157161
}
158162

159163
func (hl *genericHandlerList) add(ie *pb.Interest, h *handler) (bool, error) {
164+
if h == nil {
165+
return false, fmt.Errorf("cannot add nil generic handler")
166+
}
160167
hl.Lock()
161168
if _, ok := hl.handlers[h]; ok {
162169
hl.Unlock()

events/producer/events_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ func TestRegister(t *testing.T) {
127127

128128
// attempt to register handlers (invalid type or nil handlers)
129129
assert.Error(t, registerHandler(&peer.Interest{EventType: 100}, nil))
130+
assert.Error(t, registerHandler(&peer.Interest{EventType: peer.EventType_BLOCK}, nil))
131+
assert.Error(t, registerHandler(&peer.Interest{EventType: peer.EventType_CHAINCODE}, nil))
130132

131133
// attempt to register valid handler
132134
recvChan := make(chan *streamEvent)

0 commit comments

Comments
 (0)