Skip to content

Commit b3c1430

Browse files
author
Jason Yellick
committed
[FAB-5525] Fix configtx memory allocation bug
The configtx code uses an 'append(...)' against a slice, and records the new slice address when computing the config map. Through sheer dumb luck, this code works for config groups which are only nested 2 levels deep, because the append call triggers a true new memory allocation. However, for config groups 3 levels deep (such as consortium groups), the append call actually re-uses the underlying memory for the slice. This causes the path to be corrupted internally for the consortium group items, and cause the wrong policy to be resolved when checking for a policy which has been specified relatively. This fix manually allocates new memory, copies it, and then appends the element. Change-Id: I0f4df619e006cdfebba60173156bda597d42a544 Signed-off-by: Jason Yellick <[email protected]>
1 parent 3e4ae31 commit b3c1430

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

common/configtx/configmap.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ func recurseConfig(result map[string]comparable, path []string, group *cb.Config
8383
}
8484

8585
for key, group := range group.Groups {
86-
nextPath := append(path, key)
86+
nextPath := make([]string, len(path)+1)
87+
copy(nextPath, path)
88+
nextPath[len(nextPath)-1] = key
8789
if err := recurseConfig(result, nextPath, group); err != nil {
8890
return err
8991
}

common/configtx/configmap_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ func TestBadKey(t *testing.T) {
2929
"Should have errored on key with illegal characters")
3030
}
3131

32+
func TestConfigMapMultiGroup(t *testing.T) {
33+
config := cb.NewConfigGroup()
34+
config.Groups["0"] = cb.NewConfigGroup()
35+
config.Groups["0"].Groups["1"] = cb.NewConfigGroup()
36+
config.Groups["0"].Groups["1"].Groups["2.1"] = cb.NewConfigGroup()
37+
config.Groups["0"].Groups["1"].Groups["2.1"].Values["Value"] = &cb.ConfigValue{}
38+
config.Groups["0"].Groups["1"].Groups["2.2"] = cb.NewConfigGroup()
39+
config.Groups["0"].Groups["1"].Groups["2.2"].Values["Value"] = &cb.ConfigValue{}
40+
41+
confMap, err := MapConfig(config)
42+
assert.NoError(t, err)
43+
assert.Equal(t, []string{"Channel", "0", "1", "2.1"}, confMap["[Values] /Channel/0/1/2.1/Value"].path)
44+
assert.Equal(t, []string{"Channel", "0", "1", "2.2"}, confMap["[Values] /Channel/0/1/2.2/Value"].path)
45+
}
46+
3247
func TestConfigMap(t *testing.T) {
3348
config := cb.NewConfigGroup()
3449
config.Groups["0DeepGroup"] = cb.NewConfigGroup()

0 commit comments

Comments
 (0)