Skip to content

Commit 5f2682a

Browse files
committed
rpcserver: add missing length checks
1 parent 549d5f9 commit 5f2682a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

rpcserver.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -4638,16 +4638,28 @@ func UnmarshalUniID(rpcID *unirpc.ID) (universe.Identifier, error) {
46384638
}
46394639
switch {
46404640
case rpcID.GetAssetId() != nil:
4641+
rpcAssetID := rpcID.GetAssetId()
4642+
if len(rpcAssetID) != sha256.Size {
4643+
return universe.Identifier{}, fmt.Errorf("asset ID " +
4644+
"must be 32 bytes")
4645+
}
4646+
46414647
var assetID asset.ID
4642-
copy(assetID[:], rpcID.GetAssetId())
4648+
copy(assetID[:], rpcAssetID)
46434649

46444650
return universe.Identifier{
46454651
AssetID: assetID,
46464652
ProofType: proofType,
46474653
}, nil
46484654

46494655
case rpcID.GetAssetIdStr() != "":
4650-
assetIDBytes, err := hex.DecodeString(rpcID.GetAssetIdStr())
4656+
rpcAssetIDStr := rpcID.GetAssetIdStr()
4657+
if len(rpcAssetIDStr) != sha256.Size*2 {
4658+
return universe.Identifier{}, fmt.Errorf("asset ID string " +
4659+
"must be 64 bytes")
4660+
}
4661+
4662+
assetIDBytes, err := hex.DecodeString(rpcAssetIDStr)
46514663
if err != nil {
46524664
return universe.Identifier{}, err
46534665
}

0 commit comments

Comments
 (0)