Skip to content

Commit

Permalink
[FAB-6712] Fix re-used pointer in proto txlation
Browse files Browse the repository at this point in the history
The protolator framework depends on anotations made in go code to the
proto messages to determine how to properly marshal and unmarshal opaque
fields.  This code is supposed to return a new proto message in response
to a call for a particular opaque field.  However, for the Envelope data
field, the same pointer (and not a new proto message) was returned every
time.

This could cause data from a previous translation to persist into
subsequent ones, causing unusual failures.  This CR fixes the function
to return a clone of the pointer, rather than the pointer directly.

This CR also fixes a log message bug in the configtxupdate example, as
well as a statically referenced filename that should have been pulled
from an env variable.

It also annotates the signature header with the correct opaque types
which was required for debugging this problem but is generally useful.

Change-Id: I44c48b01d0095c7175e6e07e70d464c6d39f2f21
Signed-off-by: Jason Yellick <[email protected]>
  • Loading branch information
Jason Yellick committed Oct 20, 2017
1 parent 9cea8c7 commit 70c467f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/configtxupdate/bootstrap_batchsize/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bigMsg "Decoding genesis block"
decode common.Block "${GENESIS_BLOCK_PB}" "${GENESIS_BLOCK_JSON}"

bigMsg "Updating the genesis config"
ORIGINAL_BATCHSIZE=$(jq ".data.data[0].payload.data.config.channel_group.groups.Orderer.values.BatchSize.value.max_message_count" genesis_block.json)
ORIGINAL_BATCHSIZE=$(jq ".data.data[0].payload.data.config.channel_group.groups.Orderer.values.BatchSize.value.max_message_count" ${GENESIS_BLOCK_JSON})
NEW_BATCHSIZE=$(( ${ORIGINAL_BATCHSIZE} + 1 ))
echo "Updating batch size from ${ORIGINAL_BATCHSIZE} to ${NEW_BATCHSIZE}."
echo -e "Executing\n\tjq '.data.data[0].payload.data.config.channel_group.groups.Orderer.values.BatchSize.value.max_message_count = ${NEW_BATCHSIZE}' '${GENESIS_BLOCK_JSON}' > '${UPDATED_GENESIS_BLOCK_JSON}'"
Expand Down
2 changes: 1 addition & 1 deletion examples/configtxupdate/common_scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ encode() {
OUTPUT_FILE=$3

echo Executing:
echo -e "\t" curl -X POST --data-binary @${INPUT_FILE} "$CONFIGTXLATOR_URL/protolator/decode/${MSG_TYPE} > ${OUTPUT_FILE}"
echo -e "\t" curl -X POST --data-binary @${INPUT_FILE} "$CONFIGTXLATOR_URL/protolator/encode/${MSG_TYPE} > ${OUTPUT_FILE}"

curl -s -X POST --data-binary @${INPUT_FILE} "$CONFIGTXLATOR_URL/protolator/encode/${MSG_TYPE}" > "${OUTPUT_FILE}"
[ $? -eq 0 ] || die "unable to encode via REST"
Expand Down
16 changes: 15 additions & 1 deletion protos/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/protos/msp"
)

func (e *Envelope) StaticallyOpaqueFields() []string {
Expand Down Expand Up @@ -46,7 +47,7 @@ func (p *Payload) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
}

if msg, ok := PayloadDataMap[ch.Type]; ok {
return msg, nil
return proto.Clone(msg), nil
}
return nil, fmt.Errorf("decoding type %v is unimplemented", ch.Type)
}
Expand All @@ -66,6 +67,19 @@ func (h *Header) StaticallyOpaqueFieldProto(name string) (proto.Message, error)
}
}

func (sh *SignatureHeader) StaticallyOpaqueFields() []string {
return []string{"creator"}
}

func (sh *SignatureHeader) StaticallyOpaqueFieldProto(name string) (proto.Message, error) {
switch name {
case sh.StaticallyOpaqueFields()[0]: // channel_header
return &msp.SerializedIdentity{}, nil
default:
return nil, fmt.Errorf("unknown header field: %s", name)
}
}

func (bd *BlockData) StaticallyOpaqueSliceFields() []string {
return []string{"data"}
}
Expand Down
2 changes: 1 addition & 1 deletion protos/common/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ message ChannelHeader {
}

message SignatureHeader {
// Creator of the message, specified as a certificate chain
// Creator of the message, a marshaled msp.SerializedIdentity
bytes creator = 1;

// Arbitrary number that may only be used once. Can be used to detect replay attacks.
Expand Down

0 comments on commit 70c467f

Please sign in to comment.