Skip to content

Commit 61b0d6a

Browse files
committed
C++: Fix Iterator.qll non-member operator+= charpred.
1 parent da06b2a commit 61b0d6a

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

cpp/ql/src/semmle/code/cpp/models/implementations/Iterator.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ private class IteratorSubOperator extends Operator, TaintFunction {
157157
* A non-member `operator+=` or `operator-=` function for an iterator type.
158158
*/
159159
private class IteratorAssignArithmeticOperator extends Operator, DataFlowFunction, TaintFunction {
160+
FunctionInput iteratorInput;
161+
160162
IteratorAssignArithmeticOperator() {
161163
this.hasName(["operator+=", "operator-="]) and
162-
this.getDeclaringType() instanceof Iterator
164+
iteratorInput = getIteratorArgumentInput(this, 0)
163165
}
164166

165167
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,11 +3238,15 @@
32383238
| standalone_iterators.cpp:116:10:116:14 | call to begin | standalone_iterators.cpp:120:2:120:3 | it | |
32393239
| standalone_iterators.cpp:116:10:116:14 | call to begin | standalone_iterators.cpp:121:7:121:8 | it | |
32403240
| standalone_iterators.cpp:117:7:117:8 | it [post update] | standalone_iterators.cpp:122:7:122:8 | c1 | |
3241+
| standalone_iterators.cpp:118:2:118:3 | it | standalone_iterators.cpp:118:5:118:5 | call to operator+= | |
32413242
| standalone_iterators.cpp:118:2:118:3 | ref arg it | standalone_iterators.cpp:119:7:119:8 | it | |
32423243
| standalone_iterators.cpp:118:2:118:3 | ref arg it | standalone_iterators.cpp:120:2:120:3 | it | |
32433244
| standalone_iterators.cpp:118:2:118:3 | ref arg it | standalone_iterators.cpp:121:7:121:8 | it | |
32443245
| standalone_iterators.cpp:118:2:118:3 | ref arg it | standalone_iterators.cpp:122:7:122:8 | c1 | |
3246+
| standalone_iterators.cpp:118:8:118:8 | 1 | standalone_iterators.cpp:118:2:118:3 | ref arg it | TAINT |
3247+
| standalone_iterators.cpp:120:2:120:3 | it | standalone_iterators.cpp:120:5:120:5 | call to operator+= | |
32453248
| standalone_iterators.cpp:120:2:120:3 | ref arg it | standalone_iterators.cpp:121:7:121:8 | it | |
3249+
| standalone_iterators.cpp:120:8:120:13 | call to source | standalone_iterators.cpp:120:2:120:3 | ref arg it | TAINT |
32463250
| stl.h:75:8:75:8 | Unknown literal | stl.h:75:8:75:8 | constructor init of field container | TAINT |
32473251
| stl.h:75:8:75:8 | Unknown literal | stl.h:75:8:75:8 | constructor init of field container | TAINT |
32483252
| stl.h:75:8:75:8 | this | stl.h:75:8:75:8 | constructor init of field container [pre-this] | |
@@ -3922,12 +3926,10 @@
39223926
| string.cpp:408:8:408:9 | i2 | string.cpp:409:10:409:11 | i7 | |
39233927
| string.cpp:409:10:409:11 | i7 | string.cpp:409:12:409:12 | call to operator+= | |
39243928
| string.cpp:409:12:409:12 | call to operator+= | string.cpp:409:8:409:8 | call to operator* | TAINT |
3925-
| string.cpp:409:14:409:14 | 1 | string.cpp:409:12:409:12 | call to operator+= | |
39263929
| string.cpp:410:8:410:9 | i2 | string.cpp:410:3:410:9 | ... = ... | |
39273930
| string.cpp:410:8:410:9 | i2 | string.cpp:411:10:411:11 | i8 | |
39283931
| string.cpp:411:10:411:11 | i8 | string.cpp:411:12:411:12 | call to operator-= | |
39293932
| string.cpp:411:12:411:12 | call to operator-= | string.cpp:411:8:411:8 | call to operator* | TAINT |
3930-
| string.cpp:411:14:411:14 | 1 | string.cpp:411:12:411:12 | call to operator-= | |
39313933
| string.cpp:413:8:413:9 | s2 | string.cpp:413:11:413:13 | call to end | TAINT |
39323934
| string.cpp:413:11:413:13 | call to end | string.cpp:413:3:413:15 | ... = ... | |
39333935
| string.cpp:413:11:413:13 | call to end | string.cpp:414:5:414:6 | i9 | |
@@ -7580,11 +7582,9 @@
75807582
| vector.cpp:528:3:528:4 | ref arg it | vector.cpp:529:9:529:10 | it | |
75817583
| vector.cpp:528:3:528:4 | ref arg it | vector.cpp:530:3:530:4 | it | |
75827584
| vector.cpp:528:3:528:4 | ref arg it | vector.cpp:531:9:531:10 | it | |
7583-
| vector.cpp:528:9:528:9 | 1 | vector.cpp:528:6:528:6 | call to operator+= | |
75847585
| vector.cpp:529:9:529:10 | it | vector.cpp:529:8:529:8 | call to operator* | TAINT |
75857586
| vector.cpp:530:3:530:4 | it | vector.cpp:530:6:530:6 | call to operator+= | |
75867587
| vector.cpp:530:3:530:4 | ref arg it | vector.cpp:531:9:531:10 | it | |
7587-
| vector.cpp:530:9:530:14 | call to source | vector.cpp:530:6:530:6 | call to operator+= | |
75887588
| vector.cpp:531:9:531:10 | it | vector.cpp:531:8:531:8 | call to operator* | TAINT |
75897589
| vector.cpp:532:8:532:9 | ref arg vs | vector.cpp:533:2:533:2 | vs | |
75907590
| vector.cpp:532:8:532:9 | vs | vector.cpp:532:10:532:10 | call to operator[] | TAINT |

cpp/ql/test/library-tests/dataflow/taint-tests/standalone_iterators.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ void test_nonmember_iterator() {
118118
it += 1;
119119
sink(it);
120120
it += source();
121-
sink(it); // $ MISSING: ast,ir
121+
sink(it); // $ ast,ir
122122
sink(c1);
123123
}

0 commit comments

Comments
 (0)