Skip to content

Insecure use of lstrcpyn family functions

Description

The `lstrcpyn` family of functions do not always check for invalid pointers or check if there is sufficient space prior to copying, leading to potential overflows. More secure versions of these functions should be used.

Examples

Insecure Code

c
lstrcpyn(dest, src, count);

Secure Code

c
strncpy-s(dest, count, src, count);

Remediation

Use secure versions of these functions, such as those provided by the C Runtime Library (CRT), like `strncpy-s`, `wcsncpy-s`, `mbsncpy-s`.

Rule Details

FieldValue
IDCODE-0572
CategoryInjection
SeverityHIGH
CWECWE-120
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagsbuffer overflow, insecure function
OWASPA1:2017-Injection, A03:2021-Injection