Skip to content

Commit 9c1b6ef

Browse files
author
Jason Yellick
committed
[FAB-4463] Fix nil dereference in cauthdsl
When a specially malformed config transaction is submitted, it is possible to trick cauthdsl into attempting to compile a nil signature policy. This could result in a crash. This CR checks for a nil signature policy, and adds a test case for this condition. It also slightly enhances the logging in the package. Change-Id: I78194e13fc94c2715db169121dbff9ea4387f69b Signed-off-by: Jason Yellick <[email protected]>
1 parent d25b994 commit 9c1b6ef

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

common/cauthdsl/cauthdsl.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ var cauthdslLogger = flogging.MustGetLogger("cauthdsl")
2929

3030
// compile recursively builds a go evaluatable function corresponding to the policy specified
3131
func compile(policy *cb.SignaturePolicy, identities []*mb.MSPPrincipal, deserializer msp.IdentityDeserializer) (func([]*cb.SignedData, []bool) bool, error) {
32+
if policy == nil {
33+
return nil, fmt.Errorf("Empty policy element")
34+
}
35+
3236
switch t := policy.Type.(type) {
3337
case *cb.SignaturePolicy_NOutOf_:
3438
policies := make([]func([]*cb.SignedData, []bool) bool, len(t.NOutOf.Rules))
@@ -81,10 +85,11 @@ func compile(policy *cb.SignaturePolicy, identities []*mb.MSPPrincipal, deserial
8185
cauthdslLogger.Debugf("Principal matched by identity: (%v) for %v", t, sd.Identity)
8286
err = identity.Verify(sd.Data, sd.Signature)
8387
if err == nil {
84-
cauthdslLogger.Debugf("Principal evaluation succeeds: (%v) (used %v)", t, used)
8588
used[i] = true
89+
cauthdslLogger.Debugf("Principal evaluation succeeds: (%v) (used %v)", t, used)
8690
return true
8791
}
92+
cauthdslLogger.Debugf("Invalid signature for identity: (%v)", t)
8893
} else {
8994
cauthdslLogger.Debugf("Identity (%v) does not satisfy principal: %s", sd.Identity, err)
9095
}

common/cauthdsl/cauthdsl_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import (
2222
"testing"
2323

2424
"github.com/hyperledger/fabric/msp"
25-
26-
"github.com/golang/protobuf/proto"
2725
cb "github.com/hyperledger/fabric/protos/common"
2826
mb "github.com/hyperledger/fabric/protos/msp"
27+
28+
"github.com/golang/protobuf/proto"
29+
"github.com/stretchr/testify/assert"
2930
)
3031

3132
var invalidSignature = []byte("badsigned")
@@ -168,3 +169,8 @@ func TestNegatively(t *testing.T) {
168169
t.Fatal("Should have errored compiling because the Type field was nil")
169170
}
170171
}
172+
173+
func TestNilSignaturePolicyEnvelope(t *testing.T) {
174+
_, err := compile(nil, nil, &mockDeserializer{})
175+
assert.Error(t, err, "Fail to compile")
176+
}

0 commit comments

Comments
 (0)