Skip to content

Insecure use of alloca()

Description

The use of alloca() is unsafe because it cannot ensure that the pointer returned points to a valid and usable block of memory. The allocation made may exceed the bounds of the stack, or even go further into other objects in memory, and alloca() cannot determine such an error.

Examples

Insecure Code

c
void func() { int* p = alloca(10); }

Secure Code

c
void func() { int* p = malloc(10 * sizeof(int)); free(p); }

Remediation

Use dynamic memory allocation functions like malloc() or calloc() instead of alloca() to ensure memory safety.

Rule Details

FieldValue
IDCODE-0663
CategoryGeneric
SeverityCRITICAL
CWECWE-676
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsmemory-safety
OWASPN/A

References