Skip to content

Commit 0244aa3

Browse files
committed
rpcserver: add length checks to UnmarshalUniID
1 parent 0fbe6b3 commit 0244aa3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

rpcserver.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4667,16 +4667,28 @@ func UnmarshalUniID(rpcID *unirpc.ID) (universe.Identifier, error) {
46674667
}
46684668
switch {
46694669
case rpcID.GetAssetId() != nil:
4670+
rpcAssetID := rpcID.GetAssetId()
4671+
if len(rpcAssetID) != sha256.Size {
4672+
return universe.Identifier{}, fmt.Errorf("asset ID " +
4673+
"must be 32 bytes")
4674+
}
4675+
46704676
var assetID asset.ID
4671-
copy(assetID[:], rpcID.GetAssetId())
4677+
copy(assetID[:], rpcAssetID)
46724678

46734679
return universe.Identifier{
46744680
AssetID: assetID,
46754681
ProofType: proofType,
46764682
}, nil
46774683

46784684
case rpcID.GetAssetIdStr() != "":
4679-
assetIDBytes, err := hex.DecodeString(rpcID.GetAssetIdStr())
4685+
rpcAssetIDStr := rpcID.GetAssetIdStr()
4686+
if len(rpcAssetIDStr) != sha256.Size*2 {
4687+
return universe.Identifier{}, fmt.Errorf("asset ID string " +
4688+
"must be 64 bytes")
4689+
}
4690+
4691+
assetIDBytes, err := hex.DecodeString(rpcAssetIDStr)
46804692
if err != nil {
46814693
return universe.Identifier{}, err
46824694
}

0 commit comments

Comments
 (0)