Skip to content

Stack-based buffer overflow

Description

The software directly writes into a stack buffer, which might lead to a stack-based buffer overflow. This can cause the program to crash or potentially allow an attacker to execute arbitrary code.

Examples

Insecure Code

c
char buf[10]; strcpy(buf, "hello world");

Secure Code

c
char buf[20]; strncpy(buf, "hello world", 19); buf[19] = '\0';

Remediation

Use secure functions like snprintf or strcpy_s instead of strcpy, and ensure that the destination buffer is large enough to hold the copied string.

Rule Details

FieldValue
IDCODE-0098
CategoryInjection
SeverityCRITICAL
CWECWE-121
ConfidenceMEDIUM
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagsbuffer overflow, stack-based
OWASPN/A

References