Skip to content

Insecure string processing function

Description

The `StrCpy` family of functions do not guarantee the final string to be null terminated. Consider using one of the following alternatives `StringCbCopy`, `StringCbCopyEx`, `StringCbCopyN`, `StringCbCopyNEx`, `StringCchCopy`, `StringCchCopyEx`, `StringCchCopyN`, or `StringCchCopyNEx`. If developing for C Runtime Library (CRT), more secure versions of these functions should be used.

Examples

Insecure Code

c
strcpyA(dest, src);

Secure Code

c
StringCbCopy(dest, sizeof(dest), src);

Remediation

Replace insecure string processing functions with secure alternatives like `StringCbCopy`, `StringCbCopyEx`, `StringCbCopyN`, `StringCbCopyNEx`, `StringCchCopy`, `StringCchCopyEx`, `StringCchCopyN`, or `StringCchCopyNEx`.

Rule Details

FieldValue
IDCODE-0580
CategoryInjection
SeverityHIGH
CWECWE-120
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagsstring processing, null termination
OWASPA1:2017-Injection, A03:2021-Injection