Skip to content

Incorrect use of memset

Description

The invocation of memset() is easy to get wrong. The second argument is the character and the third argument is the size, but sometimes these arguments are in the wrong order. This results in a no-op.

Examples

Insecure Code

c
memset(buf, 0, sizeof(buf));

Secure Code

c
memset(buf, '\0', sizeof(buf));

Remediation

Verify the order of arguments in memset() and ensure the character is the second argument and the size is the third argument.

Rule Details

FieldValue
IDCODE-0647
CategoryGeneric
SeverityHIGH
CWECWE-688
ConfidenceHIGH
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityEASY
Tagsmemset, memory
OWASPN/A

References