Skip to content

Commit

Permalink
[FAB-3955] Event producer registers nil handlers
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
wlahti committed May 17, 2017
1 parent 8629463 commit 04ffb5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions events/producer/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ type chaincodeHandlerList struct {
}

func (hl *chaincodeHandlerList) add(ie *pb.Interest, h *handler) (bool, error) {
if h == nil {
return false, fmt.Errorf("cannot add nil chaincode handler")
}

hl.Lock()
defer hl.Unlock()

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

func (hl *genericHandlerList) add(ie *pb.Interest, h *handler) (bool, error) {
if h == nil {
return false, fmt.Errorf("cannot add nil generic handler")
}
hl.Lock()
if _, ok := hl.handlers[h]; ok {
hl.Unlock()
Expand Down
2 changes: 2 additions & 0 deletions events/producer/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func TestRegister(t *testing.T) {

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

// attempt to register valid handler
recvChan := make(chan *streamEvent)
Expand Down

0 comments on commit 04ffb5c

Please sign in to comment.