Skip to content

Commit 9b37c12

Browse files
committed
[FAB-5529] Missing check at endorser
There is a missing check in the endorser code for a nil chaincodeID. Added a test. Change-Id: I10cb58ddb49cb9768aa2cdb9e9dc0b24808a5fbc Signed-off-by: yacovm <[email protected]>
1 parent 1bef02c commit 9b37c12

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

core/common/validation/msgvalidation.go

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ func validateChaincodeProposalMessage(prop *pb.Proposal, hdr *common.Header) (*p
4444
return nil, errors.New("Invalid header extension for type CHAINCODE")
4545
}
4646

47+
if chaincodeHdrExt.ChaincodeId == nil {
48+
return nil, errors.New("ChaincodeHeaderExtension.ChaincodeId is nil")
49+
}
50+
4751
putilsLogger.Debugf("validateChaincodeProposalMessage info: header extension references chaincode %s", chaincodeHdrExt.ChaincodeId)
4852

4953
// - ensure that the chaincodeID is correct (?)

core/endorser/endorser_test.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ limitations under the License.
1717
package endorser
1818

1919
import (
20+
"encoding/hex"
21+
"errors"
2022
"flag"
2123
"fmt"
2224
"io/ioutil"
2325
"net"
2426
"os"
27+
"path/filepath"
2528
"runtime"
2629
"strings"
2730
"testing"
2831
"time"
2932

30-
"path/filepath"
31-
32-
"errors"
33-
3433
"github.com/golang/protobuf/proto"
34+
"github.com/hyperledger/fabric/bccsp"
3535
"github.com/hyperledger/fabric/bccsp/factory"
3636
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
3737
"github.com/hyperledger/fabric/common/policies"
@@ -50,10 +50,9 @@ import (
5050
pb "github.com/hyperledger/fabric/protos/peer"
5151
pbutils "github.com/hyperledger/fabric/protos/utils"
5252
"github.com/spf13/viper"
53+
"github.com/stretchr/testify/assert"
5354
"golang.org/x/net/context"
5455
"google.golang.org/grpc"
55-
56-
"github.com/stretchr/testify/assert"
5756
"google.golang.org/grpc/credentials"
5857
)
5958

@@ -629,6 +628,20 @@ func TestWritersACLFail(t *testing.T) {
629628
chaincode.GetChain().Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: chaincodeID}})
630629
}
631630

631+
func TestHeaderExtensionNoChaincodeID(t *testing.T) {
632+
creator, _ := signer.Serialize()
633+
nonce := []byte{1, 2, 3}
634+
digest, err := factory.GetDefault().Hash(append(nonce, creator...), &bccsp.SHA256Opts{})
635+
txID := hex.EncodeToString(digest)
636+
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeId: nil, Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs()}}
637+
invocation := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
638+
prop, _, _ := pbutils.CreateChaincodeProposalWithTxIDNonceAndTransient(txID, common.HeaderType_ENDORSER_TRANSACTION, util.GetTestChainID(), invocation, []byte{1, 2, 3}, creator, nil)
639+
signedProp, _ := getSignedProposal(prop, signer)
640+
_, err = endorserServer.ProcessProposal(context.Background(), signedProp)
641+
assert.Error(t, err)
642+
assert.Contains(t, err.Error(), "ChaincodeHeaderExtension.ChaincodeId is nil")
643+
}
644+
632645
// TestAdminACLFail deploys tried to deploy a chaincode;
633646
// however we inject a special policy for admins to simulate
634647
// the scenario in which the creator of this proposal is not among

0 commit comments

Comments
 (0)