Skip to content

Commit

Permalink
[FAB-12438] Fix NPE at deliverSupport.GetChain
Browse files Browse the repository at this point in the history
FAB-12335 Dropped the boolean value, but a nil value
that is returned as an interface without an explicit
"return nil" is returned as a "nil interface type" pointer
and expressions such as "pt == nil" are evaluated to false,
which causes a NPE.

Change-Id: Ieaaa0e8731b6588eeab7f994fe3864c3bb9f7f4b
Signed-off-by: yacovm <yacovm@il.ibm.com>
  • Loading branch information
yacovm authored and sykesm committed Oct 12, 2018
1 parent b6218b1 commit 9b6ae1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion orderer/common/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ type deliverSupport struct {
}

func (ds deliverSupport) GetChain(chainID string) deliver.Chain {
return ds.Registrar.GetChain(chainID)
chain := ds.Registrar.GetChain(chainID)
if chain == nil {
return nil
}
return chain
}

type server struct {
Expand Down
9 changes: 9 additions & 0 deletions orderer/common/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
ab "github.com/hyperledger/fabric/protos/orderer"
"github.com/hyperledger/fabric/protos/utils"

"github.com/hyperledger/fabric/orderer/common/multichannel"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/peer"
Expand Down Expand Up @@ -149,3 +150,11 @@ func TestDeliverMsgTrace(t *testing.T) {
}
}, t)
}

func TestDeliverNoChannel(t *testing.T) {
r := &multichannel.Registrar{}
ds := &deliverSupport{Registrar: r}
chain := ds.GetChain("mychannel")
assert.Nil(t, chain)
assert.True(t, chain == nil)
}

0 comments on commit 9b6ae1c

Please sign in to comment.