Skip to content

Pointer Subtraction

Description

The software subtracts one pointer from another to determine size, but this calculation can be incorrect if the pointers do not exist in the same memory chunk.

Examples

Insecure Code

c
size = (char *)ptr1 - (char *)ptr2;

Secure Code

c
size = sizeof(struct example);

Remediation

Ensure that pointers being subtracted exist in the same memory chunk or use a safer method to calculate size.

Rule Details

FieldValue
IDCODE-0264
CategoryGeneric
SeverityMEDIUM
CWECWE-469
ConfidenceMEDIUM
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tags
OWASPN/A

References