Skip to content

Commit 6b75101

Browse files
author
Jason Yellick
committed
[FAB-4464] Fix configtx manager nil dereference
When sending a specially crafted malformed configtx, it is possible to trick the configtx manager into dereferencing a nil pointer for the channel group. This CR adds a check to guard against this, and adds a test case to cover it. Change-Id: I3b6bdb464f931214819cd582ba72df938d3eeee3 Signed-off-by: Jason Yellick <[email protected]>
1 parent 9c1b6ef commit 6b75101

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

common/configtx/manager.go

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ func NewManagerImpl(envConfig *cb.Envelope, initializer api.Initializer, callOnU
9898
return nil, fmt.Errorf("Nil config envelope Config")
9999
}
100100

101+
if configEnv.Config.ChannelGroup == nil {
102+
return nil, fmt.Errorf("nil channel group")
103+
}
104+
101105
if err := validateChainID(header.ChannelId); err != nil {
102106
return nil, fmt.Errorf("Bad channel id: %s", err)
103107
}

common/configtx/manager_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,23 @@ func TestCallback(t *testing.T) {
133133
}
134134
}
135135

136+
func TestEmptyChannel(t *testing.T) {
137+
_, err := NewManagerImpl(&cb.Envelope{
138+
Payload: utils.MarshalOrPanic(&cb.Payload{
139+
Header: &cb.Header{
140+
ChannelHeader: utils.MarshalOrPanic(&cb.ChannelHeader{
141+
Type: int32(cb.HeaderType_CONFIG),
142+
ChannelId: "foo",
143+
}),
144+
},
145+
Data: utils.MarshalOrPanic(&cb.ConfigEnvelope{
146+
Config: &cb.Config{},
147+
}),
148+
}),
149+
}, defaultInitializer(), nil)
150+
assert.Error(t, err)
151+
}
152+
136153
// TestDifferentChainID tests that a config update for a different chain ID fails
137154
func TestDifferentChainID(t *testing.T) {
138155
cm, err := NewManagerImpl(

0 commit comments

Comments
 (0)