Skip to content

Commit

Permalink
[FAB-5529] Missing check at endorser
Browse files Browse the repository at this point in the history
There is a missing check in the endorser code for a nil chaincodeID.
Added a test.

Change-Id: I10cb58ddb49cb9768aa2cdb9e9dc0b24808a5fbc
Signed-off-by: yacovm <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Jul 29, 2017
1 parent 1bef02c commit 9b37c12
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions core/common/validation/msgvalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func validateChaincodeProposalMessage(prop *pb.Proposal, hdr *common.Header) (*p
return nil, errors.New("Invalid header extension for type CHAINCODE")
}

if chaincodeHdrExt.ChaincodeId == nil {
return nil, errors.New("ChaincodeHeaderExtension.ChaincodeId is nil")
}

putilsLogger.Debugf("validateChaincodeProposalMessage info: header extension references chaincode %s", chaincodeHdrExt.ChaincodeId)

// - ensure that the chaincodeID is correct (?)
Expand Down
25 changes: 19 additions & 6 deletions core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ limitations under the License.
package endorser

import (
"encoding/hex"
"errors"
"flag"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"

"path/filepath"

"errors"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/bccsp/factory"
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
"github.com/hyperledger/fabric/common/policies"
Expand All @@ -50,10 +50,9 @@ import (
pb "github.com/hyperledger/fabric/protos/peer"
pbutils "github.com/hyperledger/fabric/protos/utils"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
"google.golang.org/grpc"

"github.com/stretchr/testify/assert"
"google.golang.org/grpc/credentials"
)

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

func TestHeaderExtensionNoChaincodeID(t *testing.T) {
creator, _ := signer.Serialize()
nonce := []byte{1, 2, 3}
digest, err := factory.GetDefault().Hash(append(nonce, creator...), &bccsp.SHA256Opts{})
txID := hex.EncodeToString(digest)
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeId: nil, Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs()}}
invocation := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
prop, _, _ := pbutils.CreateChaincodeProposalWithTxIDNonceAndTransient(txID, common.HeaderType_ENDORSER_TRANSACTION, util.GetTestChainID(), invocation, []byte{1, 2, 3}, creator, nil)
signedProp, _ := getSignedProposal(prop, signer)
_, err = endorserServer.ProcessProposal(context.Background(), signedProp)
assert.Error(t, err)
assert.Contains(t, err.Error(), "ChaincodeHeaderExtension.ChaincodeId is nil")
}

// TestAdminACLFail deploys tried to deploy a chaincode;
// however we inject a special policy for admins to simulate
// the scenario in which the creator of this proposal is not among
Expand Down

0 comments on commit 9b37c12

Please sign in to comment.