CWE-469: Use of Pointer Subtraction to Determine Size
The product subtracts one pointer from another in order to determine size, but this calculation can be incorrect if the pointers do not exist in the same memory chunk.
How it's found
Use of Pointer Subtraction to Determine Size is typically found by tracing untrusted input from where it enters the system to the point where it is used without the check or neutralization this weakness describes, combining manual code review with dynamic testing.
Vulnerable vs. safe
int data;struct node* next;
tail = current;current = current->next;struct node* current = head;struct node* tail;while (current != NULL) {}return tail - head;
// Returns the number of nodes in a linked list from
// the given pointer to the head of the list.
// other methods for manipulating the liststruct node {};int size(struct node* head) {}...count++;current = current->next;struct node* current = head;int count = 0;while (current != NULL) {}return count;...int size(struct node* head) {}Consequences
- Modify Memory, Read Memory, Execute Unauthorized Code or Commands, Gain Privileges or Assume Identity: There is the potential for arbitrary code execution with privileges of the vulnerable program.
Mitigations
- Implementation: Save an index variable. This is the recommended solution. Rather than subtract pointers from one another, use an index variable of the same size as the pointers in question. Use this variable to "walk" from one pointer to the other and calculate the difference. Always validate this number.
Where this fits in a TurboPentest engagement
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Frequently asked questions
What is CWE-469?
The product subtracts one pointer from another in order to determine size, but this calculation can be incorrect if the pointers do not exist in the same memory chunk.
How do you find Use of Pointer Subtraction to Determine Size?
Use of Pointer Subtraction to Determine Size is typically found by tracing untrusted input from where it enters the system to the point where it is used without the check or neutralization this weakness describes, combining manual code review with dynamic testing.
What is the impact of CWE-469?
Modify Memory, Read Memory, Execute Unauthorized Code or Commands, Gain Privileges or Assume Identity: There is the potential for arbitrary code execution with privileges of the vulnerable program.
Does TurboPentest test for Use of Pointer Subtraction to Determine Size?
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Related CWEs
Written and reviewed by
Michel Chamberland - Founder & CEO, IntegSec
CISSP, OSCP, OSCE, CEH, GIAC, CCSK · 20+ years in offensive security
Michel has spent 20+ years on offensive security teams including IBM X-Force Red and Trustwave SpiderLabs, leading penetration tests, red team engagements, and breach response for Fortune 500 customers. He is the founder of IntegSec and the architect of TurboPentest.
Find these issues before an attacker does
TurboPentest runs an agentic AI pentest against your target and reports findings with proof, from $99 per target.
Start a pentest