CWE-253: Incorrect Check of Function Return Value

Export to Word

Description

The product incorrectly checks a return value from a function, which prevents it from detecting errors or exceptional conditions.

Extended Description

Important and common functions will return some value about the success of its actions. This will alert the program whether or not to handle any errors caused by that function.


ThreatScore

Threat Mapped score: 0.0

Industry: Finiancial

Threat priority: Unclassified


Observed Examples (CVEs)

Related Attack Patterns (CAPEC)

N/A


Attack TTPs

N/A

Modes of Introduction

Phase Note
Implementation N/A

Common Consequences

Potential Mitigations

Applicable Platforms


Demonstrative Examples

Intro: This code attempts to allocate memory for 4 integers and checks if the allocation succeeds.

Body: The code assumes that only a negative return value would indicate an error, but malloc() may return a null pointer when there is an error. The value of tmp could then be equal to 0, and the error would be missed.

tmp = malloc(sizeof(int) * 4); if (tmp < 0 ) { perror("Failure"); //should have checked if the call returned 0 }

Notes

← Back to CWE list