Skip to content

Commit 108cc9e

Browse files
author
Robert Marsh
committed
C++: fix assignment to *iter++
1 parent f39195e commit 108cc9e

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/FlowVar.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,12 @@ module FlowVar_internal {
807807
def.getAnUltimateDefiningValue(iterator) = c and
808808
result = def.getAUse(iterator)
809809
)
810+
or
811+
exists(Call crement |
812+
crement = result and
813+
[crement.getQualifier(), crement.getArgument(0)] = getAnIteratorAccess(collection) and
814+
crement.getTarget().getName() = ["operator++", "operator--"]
815+
)
810816
}
811817

812818
class IteratorParameter extends Parameter {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7054,6 +7054,8 @@
70547054
| vector.cpp:402:35:402:37 | v12 | vector.cpp:402:39:402:43 | call to begin | TAINT |
70557055
| vector.cpp:402:39:402:43 | call to begin | vector.cpp:403:3:403:5 | i12 | |
70567056
| vector.cpp:402:39:402:43 | call to begin | vector.cpp:404:3:404:5 | i12 | |
7057+
| vector.cpp:403:2:403:2 | call to operator* [post update] | vector.cpp:405:7:405:9 | v12 | |
7058+
| vector.cpp:403:2:403:2 | call to operator* [post update] | vector.cpp:415:1:415:1 | v12 | |
70577059
| vector.cpp:403:2:403:11 | ... = ... | vector.cpp:403:2:403:2 | call to operator* [post update] | |
70587060
| vector.cpp:403:3:403:5 | i12 | vector.cpp:403:6:403:6 | call to operator++ | |
70597061
| vector.cpp:403:3:403:5 | ref arg i12 | vector.cpp:404:3:404:5 | i12 | |
@@ -7071,6 +7073,8 @@
70717073
| vector.cpp:407:35:407:37 | ref arg v13 | vector.cpp:415:1:415:1 | v13 | |
70727074
| vector.cpp:407:35:407:37 | v13 | vector.cpp:407:39:407:43 | call to begin | TAINT |
70737075
| vector.cpp:407:39:407:43 | call to begin | vector.cpp:408:3:408:5 | i13 | |
7076+
| vector.cpp:408:2:408:2 | call to operator* [post update] | vector.cpp:409:7:409:9 | v13 | |
7077+
| vector.cpp:408:2:408:2 | call to operator* [post update] | vector.cpp:415:1:415:1 | v13 | |
70747078
| vector.cpp:408:2:408:18 | ... = ... | vector.cpp:408:2:408:2 | call to operator* [post update] | |
70757079
| vector.cpp:408:3:408:5 | i13 | vector.cpp:408:6:408:6 | call to operator++ | |
70767080
| vector.cpp:408:6:408:6 | call to operator++ | vector.cpp:408:2:408:2 | call to operator* | TAINT |
@@ -7084,6 +7088,8 @@
70847088
| vector.cpp:411:39:411:43 | call to begin | vector.cpp:413:3:413:5 | i14 | |
70857089
| vector.cpp:412:2:412:4 | i14 | vector.cpp:412:5:412:5 | call to operator++ | |
70867090
| vector.cpp:412:2:412:4 | ref arg i14 | vector.cpp:413:3:413:5 | i14 | |
7091+
| vector.cpp:413:2:413:2 | call to operator* [post update] | vector.cpp:414:7:414:9 | v14 | |
7092+
| vector.cpp:413:2:413:2 | call to operator* [post update] | vector.cpp:415:1:415:1 | v14 | |
70877093
| vector.cpp:413:2:413:18 | ... = ... | vector.cpp:413:2:413:2 | call to operator* [post update] | |
70887094
| vector.cpp:413:3:413:5 | i14 | vector.cpp:413:6:413:6 | call to operator++ | |
70897095
| vector.cpp:413:6:413:6 | call to operator++ | vector.cpp:413:2:413:2 | call to operator* | TAINT |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,5 @@
654654
| vector.cpp:392:7:392:8 | v9 | vector.cpp:389:8:389:13 | call to source |
655655
| vector.cpp:400:7:400:9 | v11 | vector.cpp:399:38:399:43 | call to source |
656656
| vector.cpp:405:7:405:9 | v12 | vector.cpp:404:9:404:14 | call to source |
657+
| vector.cpp:409:7:409:9 | v13 | vector.cpp:408:11:408:16 | call to source |
658+
| vector.cpp:414:7:414:9 | v14 | vector.cpp:413:11:413:16 | call to source |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,5 @@
380380
| vector.cpp:392:7:392:8 | vector.cpp:389:8:389:13 | AST only |
381381
| vector.cpp:400:7:400:9 | vector.cpp:399:38:399:43 | AST only |
382382
| vector.cpp:405:7:405:9 | vector.cpp:404:9:404:14 | AST only |
383+
| vector.cpp:409:7:409:9 | vector.cpp:408:11:408:16 | AST only |
384+
| vector.cpp:414:7:414:9 | vector.cpp:413:11:413:16 | AST only |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,10 @@ void test_vector_output_iterator(int b) {
406406

407407
std::vector<int>::iterator i13 = v13.begin();
408408
*i13++ = source();
409-
sink(v13); // tainted [NOT DETECTED]
409+
sink(v13); // tainted [NOT DETECTED by IR]
410410

411411
std::vector<int>::iterator i14 = v14.begin();
412412
i14++;
413413
*i14++ = source();
414-
sink(v14); // tainted [NOT DETECTED]
414+
sink(v14); // tainted [NOT DETECTED by IR]
415415
}

0 commit comments

Comments
 (0)