Skip to content

Commit

Permalink
rpcserver: add missing length checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jharveyb committed Aug 13, 2024
1 parent 549d5f9 commit 5f2682a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4638,16 +4638,28 @@ func UnmarshalUniID(rpcID *unirpc.ID) (universe.Identifier, error) {
}
switch {
case rpcID.GetAssetId() != nil:
rpcAssetID := rpcID.GetAssetId()
if len(rpcAssetID) != sha256.Size {
return universe.Identifier{}, fmt.Errorf("asset ID " +
"must be 32 bytes")
}

var assetID asset.ID
copy(assetID[:], rpcID.GetAssetId())
copy(assetID[:], rpcAssetID)

return universe.Identifier{
AssetID: assetID,
ProofType: proofType,
}, nil

case rpcID.GetAssetIdStr() != "":
assetIDBytes, err := hex.DecodeString(rpcID.GetAssetIdStr())
rpcAssetIDStr := rpcID.GetAssetIdStr()
if len(rpcAssetIDStr) != sha256.Size*2 {
return universe.Identifier{}, fmt.Errorf("asset ID string " +
"must be 64 bytes")
}

assetIDBytes, err := hex.DecodeString(rpcAssetIDStr)
if err != nil {
return universe.Identifier{}, err
}
Expand Down

0 comments on commit 5f2682a

Please sign in to comment.