Smart Contract / Unchecked Call Return Value
Description
Unchecked Call Return Value (CWE-252) is a vulnerability in Smart Contracts that occurs when the return value from a called function is not checked and it is assumed that the return value is valid. This can lead to serious security issues, as an attacker can manipulate the return values and cause the code to behave in unexpected ways. According to the CWE directory, the Unchecked Call Return Value vulnerability is found in Software Component (SWC).
Risk
The unchecked call return value vulnerability can have a severe impact on the security of the system. If the return value is not properly checked, it can lead to security issues, such as denial of service, increased privilege, information leakage, or code injection. With the unchecked call return value vulnerability, an attacker can input malicious data and cause the code to behave in unexpected ways.
Solution
The best way to fix the unchecked call return value vulnerability is to add checks to the code that will validate the return value. In addition, the OWASP Testing Guide suggests that developers should validate the inputs for all functions, and when using third-party libraries, ensure that the inputs are validated before being passed to the library.
Example
The following code is an example of the unchecked call return value vulnerability from CVE-2019-7618.
function transfer(address to, uint256 amount) public {
// Call function to get account balance of 'to' address.
uint256 balance = getBalance(to);
// Transfer 'amount' from balance of 'to' address.
// The return value is not checked, so it is possible for the
// transfer to be successful even if the balance is not enough.
transferFrom(to, balance - amount);
}