Skip to content

Commit f367cf0

Browse files
author
Jason Yellick
committed
[FAB-4163] Nil dereference in configtxgen
When attempting to generate a genesis block while failing to specify an orderer section, the result was a nil point dereference. This CR fixes the dereference by protecting it behind a nil check, and updates the tool logic to check for the existence of the section, and print an error and exit if it is not present. Change-Id: Id768f23d7e138fd7c8ca90889e805975fdf44bec Signed-off-by: Jason Yellick <[email protected]>
1 parent 1c8dc30 commit f367cf0

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

common/configtx/tool/configtxgen/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ var logger = flogging.MustGetLogger("common/configtx/tool")
4444
func doOutputBlock(config *genesisconfig.Profile, channelID string, outputBlock string) error {
4545
pgen := provisional.New(config)
4646
logger.Info("Generating genesis block")
47+
if config.Orderer == nil {
48+
return fmt.Errorf("config does not contain an Orderers section, necessary for all config blocks, aborting")
49+
}
4750
if config.Consortiums == nil {
4851
logger.Warning("Genesis block does not contain a consortiums group definition. This block cannot be used for orderer bootstrap.")
4952
}

common/configtx/tool/configtxgen/main_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ func TestInspectBlock(t *testing.T) {
5151
assert.NoError(t, doInspectBlock(blockDest), "Good block inspection request")
5252
}
5353

54+
func TestMissingOrdererSection(t *testing.T) {
55+
blockDest := tmpDir + string(os.PathSeparator) + "block"
56+
57+
factory.InitFactories(nil)
58+
config := genesisconfig.Load(genesisconfig.SampleInsecureProfile)
59+
config.Orderer = nil
60+
61+
assert.Error(t, doOutputBlock(config, "foo", blockDest), "Missing orderer section")
62+
}
63+
5464
func TestInspectConfigTx(t *testing.T) {
5565
configTxDest := tmpDir + string(os.PathSeparator) + "configtx"
5666

common/configtx/tool/provisional/provisional.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func New(conf *genesisconfig.Profile) Generator {
8888
// Chain Config Types
8989
config.DefaultHashingAlgorithm(),
9090
config.DefaultBlockDataHashingStructure(),
91-
config.TemplateOrdererAddresses(conf.Orderer.Addresses), // TODO, move to conf.Channel when it exists
9291

9392
// Default policies
9493
policies.TemplateImplicitMetaAnyPolicy([]string{}, configvaluesmsp.ReadersPolicyKey),
@@ -99,6 +98,9 @@ func New(conf *genesisconfig.Profile) Generator {
9998

10099
if conf.Orderer != nil {
101100
bs.ordererGroups = []*cb.ConfigGroup{
101+
// Orderer addresses
102+
config.TemplateOrdererAddresses(conf.Orderer.Addresses),
103+
102104
// Orderer Config Types
103105
config.TemplateConsensusType(conf.Orderer.OrdererType),
104106
config.TemplateBatchSize(&ab.BatchSize{

0 commit comments

Comments
 (0)