...
An iterator range is a pair of iterators first and last that refer to the first element and the one-past-the-end-th element of the range, respectively. It is required that last be reachable from first by repeated increments of first.
Non-Compliant Code Example
In this non-compliant example, the two iterators that delimit the range point into the same container, but the first iterator doesn't actually precede the second.
...
Invalid iterator ranges can result from comparison functions that return true for equal values. See STL32-CPP. Use a Valid Ordering Rule and Meyers 01.
Non-Compliant Code Example
The second common case arises when the iterators point into different containers:
...
The results are similar to the first non-compliant code example.
Compliant Solution
Code Block | ||
---|---|---|
| ||
for_each( c.begin(), c.end(), Something );
|
Risk Assessment
Using an invalid iterator range is similar to allowing a buffer overflow, which can lead to an attacker running arbitrary code.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
STL31-C CPP | 3 (high) | 2 (probable) | 1 (high) | P6 | L2 |
References
Wiki Markup |
---|
\[[Sutter 05|AA. C++ References#Sutter 05]\] Item 83: Use a checked STL implementation. \[[Meyers 01|AA. C++ References#Meyers 01]\] Item 21: Always have comparison functions return false for equal values. \[[ISO/IEC 14882-2003|AA. C++ References#ISO/IEC 14882-2003]\] Section 24: Iterators Library. |
...