Skip to content

Unchecked Return Value of Memory Allocation Function

Description

The software does not check the return value from a memory allocation function, which can prevent it from detecting unexpected states and conditions, such as out-of-memory errors.

Examples

Insecure Code

c
void* ptr = malloc(10);

Secure Code

c
void* ptr = malloc(10);
if (ptr == NULL) {
    // handle error
}

Remediation

Check the return value of the memory allocation function and handle the error accordingly.

Rule Details

FieldValue
IDCODE-0767
CategoryGeneric
SeverityMEDIUM
CWECWE-252
ConfidenceMEDIUM
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsmemory-allocation, error-handling
OWASPN/A

References