Commit 923afecd authored by yacovm's avatar yacovm
Browse files

[FAB-11705] Fix deduplicateIdentity slice appending



The slice appending of deduplicateIdentity is broken with the
latest version of protobuf, as (unlike the previous in v1.2 and lower)
it doesn't allocate the minimum capacity for byte slice fields.

Change-Id: I2bfe3e0aefb549d9f1a8fa8e766018c2146512c8
Signed-off-by: default avataryacovm <yacovm@il.ibm.com>
parent 65f1c74b
......@@ -758,9 +758,12 @@ func (vscc *ValidatorOneValidSignature) deduplicateIdentity(cap *pb.ChaincodeAct
logger.Warningf("Ignoring duplicated identity, Mspid: %s, pem:\n%s", serializedIdentity.Mspid, serializedIdentity.IdBytes)
continue
}
data := make([]byte, len(prespBytes)+len(endorsement.Endorser))
copy(data, prespBytes)
copy(data[len(prespBytes):], endorsement.Endorser)
signatureSet = append(signatureSet, &common.SignedData{
// set the data that is signed; concatenation of proposal response bytes and endorser ID
Data: append(prespBytes, endorsement.Endorser...),
Data: data,
// set the identity that signs the message: it's the endorser
Identity: endorsement.Endorser,
// set the signature
......
......@@ -339,6 +339,43 @@ func newCustomValidationInstance(qec txvalidator.QueryExecutorCreator, c validat
return New(c, sf, is, pe)
}
func TestDeduplicateIdentity(t *testing.T) {
// We allocate a slice with capacity greater than the length
proposalResponsePayload := []byte{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}
prpBuff := make([]byte, len(proposalResponsePayload), len(proposalResponsePayload)*2)
copy(prpBuff, proposalResponsePayload)
identity1 := utils.MarshalOrPanic(&mspproto.SerializedIdentity{
IdBytes: []byte{1, 1, 1},
})
identity2 := utils.MarshalOrPanic(&mspproto.SerializedIdentity{
IdBytes: []byte{2, 2, 2},
})
chaincodeActionPayload := &peer.ChaincodeActionPayload{
Action: &peer.ChaincodeEndorsedAction{
Endorsements: []*peer.Endorsement{
{
Endorser: identity1,
},
{
Endorser: identity2,
},
},
ProposalResponsePayload: prpBuff,
},
}
signedData, err := (&ValidatorOneValidSignature{}).deduplicateIdentity(chaincodeActionPayload)
assert.NoError(t, err)
// The original bytes of proposalResponsePayload are preserved
assert.Equal(t, proposalResponsePayload, signedData[0].Data[:len(proposalResponsePayload)])
assert.Equal(t, proposalResponsePayload, signedData[1].Data[:len(proposalResponsePayload)])
// And are suffixed with the identity bytes
assert.Equal(t, identity1, signedData[0].Data[len(proposalResponsePayload):])
assert.Equal(t, identity2, signedData[1].Data[len(proposalResponsePayload):])
}
func TestInvoke(t *testing.T) {
v := newValidationInstance(make(map[string]map[string][]byte))
......
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