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
TurboPentest's agentic pentest is powerful and covers a broad range of issues automatically. This particular class is best confirmed in a manual IntegSec engagement, where human pentesters apply deeper methodology and a larger context window than any automated pass.
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?
TurboPentest's agentic pentest is powerful and covers a broad range of issues automatically. This particular class is best confirmed in a manual IntegSec engagement, where human pentesters apply deeper methodology and a larger context window than any automated pass.
Related CWEs
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 $99 pentest