Skip to content

Commit

Permalink
[FAB-4163] Nil dereference in configtxgen
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Jun 2, 2017
1 parent 1c8dc30 commit f367cf0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions common/configtx/tool/configtxgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ var logger = flogging.MustGetLogger("common/configtx/tool")
func doOutputBlock(config *genesisconfig.Profile, channelID string, outputBlock string) error {
pgen := provisional.New(config)
logger.Info("Generating genesis block")
if config.Orderer == nil {
return fmt.Errorf("config does not contain an Orderers section, necessary for all config blocks, aborting")
}
if config.Consortiums == nil {
logger.Warning("Genesis block does not contain a consortiums group definition. This block cannot be used for orderer bootstrap.")
}
Expand Down
10 changes: 10 additions & 0 deletions common/configtx/tool/configtxgen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ func TestInspectBlock(t *testing.T) {
assert.NoError(t, doInspectBlock(blockDest), "Good block inspection request")
}

func TestMissingOrdererSection(t *testing.T) {
blockDest := tmpDir + string(os.PathSeparator) + "block"

factory.InitFactories(nil)
config := genesisconfig.Load(genesisconfig.SampleInsecureProfile)
config.Orderer = nil

assert.Error(t, doOutputBlock(config, "foo", blockDest), "Missing orderer section")
}

func TestInspectConfigTx(t *testing.T) {
configTxDest := tmpDir + string(os.PathSeparator) + "configtx"

Expand Down
4 changes: 3 additions & 1 deletion common/configtx/tool/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func New(conf *genesisconfig.Profile) Generator {
// Chain Config Types
config.DefaultHashingAlgorithm(),
config.DefaultBlockDataHashingStructure(),
config.TemplateOrdererAddresses(conf.Orderer.Addresses), // TODO, move to conf.Channel when it exists

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

if conf.Orderer != nil {
bs.ordererGroups = []*cb.ConfigGroup{
// Orderer addresses
config.TemplateOrdererAddresses(conf.Orderer.Addresses),

// Orderer Config Types
config.TemplateConsensusType(conf.Orderer.OrdererType),
config.TemplateBatchSize(&ab.BatchSize{
Expand Down

0 comments on commit f367cf0

Please sign in to comment.