Skip to content

Commit

Permalink
[FAB-3344] Fix CSCC error messages
Browse files Browse the repository at this point in the history
This commit fixes the error messages of the CSCC:

1. JoinChannel call provided with genesis block, hence args[1] is a
block and not channel it as expected in error message, hence to prevent
putting entire block into error message, channel id is extracted
instead.

2. GetChannel doesn't get any parameters and therefore in order to avoid
panic on accessing non existing args[1], this part of error message is
removed.

Change-Id: Ifcfc543afa5d694c963a65d688056e4d072b9379
Signed-off-by: Artem Barger <bartem@il.ibm.com>
  • Loading branch information
C0rWin committed Apr 23, 2017
1 parent 88ac3ba commit ffbf604
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/scc/cscc/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ func (e *PeerConfiger) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
case JoinChain:
// 2. check local MSP Admins policy
if err = e.policyChecker.CheckPolicyNoChannel(mgmt.Admins, sp); err != nil {
return shim.Error(fmt.Sprintf("\"JoinChain\" request failed authorization check for channel [%s]: [%s]", args[1], err))
cid, e := utils.GetChainIDFromBlockBytes(args[1])
errorString := fmt.Sprintf("\"JoinChain\" request failed authorization check "+
"for channel [%s]: [%s]", cid, err)
if e != nil {
errorString = fmt.Sprintf("\"JoinChain\" request failed authorization [%s] and unable "+
"to extract channel id from the block due to [%s]", err, e)
}
return shim.Error(errorString)
}

return joinChain(args[1])
Expand All @@ -127,7 +134,7 @@ func (e *PeerConfiger) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
case GetChannels:
// 2. check local MSP Members policy
if err = e.policyChecker.CheckPolicyNoChannel(mgmt.Members, sp); err != nil {
return shim.Error(fmt.Sprintf("\"GetChannels\" request failed authorization check for channel [%s]: [%s]", args[1], err))
return shim.Error(fmt.Sprintf("\"GetChannels\" request failed authorization check: [%s]", err))
}

return getChannels()
Expand Down
10 changes: 10 additions & 0 deletions protos/utils/blockutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ import (
cb "github.com/hyperledger/fabric/protos/common"
)

// GetChainIDFromBlockBytes returns chain ID given byte array which represents the block
func GetChainIDFromBlockBytes(bytes []byte) (string, error) {
block, err := GetBlockFromBlockBytes(bytes)
if err != nil {
return "", err
}

return GetChainIDFromBlock(block)
}

// GetChainIDFromBlock returns chain ID in the block
func GetChainIDFromBlock(block *cb.Block) (string, error) {
if block.Data == nil || block.Data.Data == nil || len(block.Data.Data) == 0 {
Expand Down

0 comments on commit ffbf604

Please sign in to comment.