Skip to content

Insecure use of strncpy

Description

The `strncpy` family of functions do not properly handle strings that are not null terminated. It is recommended to use more secure alternatives such as `snprintf`.

Examples

Insecure Code

c
strncpy(dest, src, 10);

Secure Code

c
snprintf(dest, 10, "%s", src);

Remediation

Replace strncpy with a more secure alternative like snprintf.

Rule Details

FieldValue
IDCODE-0584
CategoryInjection
SeverityHIGH
CWECWE-120
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsinjection, buffer overflow
OWASPA1:2017-Injection, A03:2021-Injection