Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of input validation of arrays #111

Closed
code423n4 opened this issue Oct 27, 2021 · 2 comments
Closed

Lack of input validation of arrays #111

code423n4 opened this issue Oct 27, 2021 · 2 comments
Labels
0 (Non-critical) Code style, clarity, syntax, versioning, off-chain monitoring (events etc), exclude gas optimisation bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) duplicate This issue or pull request already exists

Comments

@code423n4
Copy link
Contributor

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-10-mochi/blob/8458209a52565875d8b2cefcb611c477cefb9253/projects/mochi-core/contracts/profile/MochiProfileV0.sol#L82-L89

function changeAssetClass(
        address[] calldata _assets,
        AssetClass[] calldata _classes
    ) external override onlyGov {
        for (uint256 i = 0; i < _assets.length; i++) {
            _assetClass[_assets[i]] = _classes[i];
        }
    }

If the array length of _assets is larger than the length of _classes, when accessing _assets[i] it will throw an out-of-range exception.

Other instances include:

https://github.com/code-423n4/2021-10-mochi/blob/8458209a52565875d8b2cefcb611c477cefb9253/projects/mochi-core/contracts/profile/MochiProfileV0.sol#L91-L98

function changeCreditCap(
    address[] calldata _assets,
    uint256[] calldata _caps
) external onlyGov {
    for (uint256 i = 0; i < _assets.length; i++) {
        creditCap[_assets[i]] = _caps[i];
    }
}

https://github.com/code-423n4/2021-10-mochi/blob/8458209a52565875d8b2cefcb611c477cefb9253/projects/mochi-cssr/contracts/adapter/ChainlinkAdapter.sol#L33-L37

function setFeed(address[] calldata _assets, address[] calldata _feeds) external onlyGov {
    for(uint256 i = 0; i<_assets.length; i++) {
        feed[_assets[i]] = AggregatorV3Interface(_feeds[i]);
    }
}

Recommendation

Consider adding checks for input validation of arrays.

For example:

function changeAssetClass(
    address[] calldata _assets,
    AssetClass[] calldata _classes
) external override onlyGov {
    require(_assets.length == _classes.length, "INVALID_ARRAYS");
    for (uint256 i = 0; i < _assets.length; i++) {
        _assetClass[_assets[i]] = _classes[i];
    }
}
@code423n4 code423n4 added 1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working labels Oct 27, 2021
code423n4 added a commit that referenced this issue Oct 27, 2021
@r2moon
Copy link
Collaborator

r2moon commented Oct 29, 2021

duplicated with #31

@r2moon r2moon added disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) duplicate This issue or pull request already exists labels Oct 29, 2021
@ghoul-sol ghoul-sol added 0 (Non-critical) Code style, clarity, syntax, versioning, off-chain monitoring (events etc), exclude gas optimisation and removed 1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments labels Nov 2, 2021
@ghoul-sol
Copy link
Collaborator

best practices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 (Non-critical) Code style, clarity, syntax, versioning, off-chain monitoring (events etc), exclude gas optimisation bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants