Skip to content

Commit

Permalink
Merge pull request #217 from hyperledger-labs/fix-denom-length-check
Browse files Browse the repository at this point in the history
Add check that denom length is sufficient for slice

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele authored Oct 9, 2023
2 parents 4787197 + 4264266 commit 321c4d8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions contracts/apps/20-transfer/ICS20Transfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract contract ICS20Transfer is IBCAppBase {

bytes memory denomPrefix = _getDenomPrefix(packet.source_port, packet.source_channel);
bytes memory denom = bytes(data.denom);
if (denom.slice(0, denomPrefix.length).equal(denomPrefix)) {
if (denom.length >= denomPrefix.length && denom.slice(0, denomPrefix.length).equal(denomPrefix)) {
// sender chain is not the source, unescrow tokens
bytes memory unprefixedDenom = denom.slice(denomPrefix.length, denom.length - denomPrefix.length);
success = _transferFrom(
Expand Down Expand Up @@ -108,13 +108,14 @@ abstract contract ICS20Transfer is IBCAppBase {
virtual
{
bytes memory denomPrefix = _getDenomPrefix(sourcePort, sourceChannel);
if (!bytes(data.denom).slice(0, denomPrefix.length).equal(denomPrefix)) {
bytes memory denom = bytes(data.denom);
if (denom.length >= denomPrefix.length && denom.slice(0, denomPrefix.length).equal(denomPrefix)) {
require(_mint(_decodeSender(data.sender), data.denom, data.amount));
} else {
// sender was source chain
require(
_transferFrom(_getEscrowAddress(sourceChannel), _decodeSender(data.sender), data.denom, data.amount)
);
} else {
require(_mint(_decodeSender(data.sender), data.denom, data.amount));
}
}

Expand Down

0 comments on commit 321c4d8

Please sign in to comment.