Commit b3c14300 authored by Jason Yellick's avatar Jason Yellick
Browse files

[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

Change-Id: I0f4df619e006cdfebba60173156bda597d42a544
Signed-off-by: default avatarJason Yellick <>
parent 3e4ae314
......@@ -83,7 +83,9 @@ func recurseConfig(result map[string]comparable, path []string, group *cb.Config
for key, group := range group.Groups {
nextPath := append(path, key)
nextPath := make([]string, len(path)+1)
copy(nextPath, path)
nextPath[len(nextPath)-1] = key
if err := recurseConfig(result, nextPath, group); err != nil {
return err
......@@ -29,6 +29,21 @@ func TestBadKey(t *testing.T) {
"Should have errored on key with illegal characters")
func TestConfigMapMultiGroup(t *testing.T) {
config := cb.NewConfigGroup()
config.Groups["0"] = cb.NewConfigGroup()
config.Groups["0"].Groups["1"] = cb.NewConfigGroup()
config.Groups["0"].Groups["1"].Groups["2.1"] = cb.NewConfigGroup()
config.Groups["0"].Groups["1"].Groups["2.1"].Values["Value"] = &cb.ConfigValue{}
config.Groups["0"].Groups["1"].Groups["2.2"] = cb.NewConfigGroup()
config.Groups["0"].Groups["1"].Groups["2.2"].Values["Value"] = &cb.ConfigValue{}
confMap, err := MapConfig(config)
assert.NoError(t, err)
assert.Equal(t, []string{"Channel", "0", "1", "2.1"}, confMap["[Values] /Channel/0/1/2.1/Value"].path)
assert.Equal(t, []string{"Channel", "0", "1", "2.2"}, confMap["[Values] /Channel/0/1/2.2/Value"].path)
func TestConfigMap(t *testing.T) {
config := cb.NewConfigGroup()
config.Groups["0DeepGroup"] = cb.NewConfigGroup()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment