Skip to content

Commit c2fd2e2

Browse files
committed
CPP: Model taint flow through std::swap.
1 parent f132bca commit c2fd2e2

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

cpp/ql/src/semmle/code/cpp/models/Models.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ private import implementations.Pure
66
private import implementations.Strcat
77
private import implementations.Strcpy
88
private import implementations.Strftime
9+
private import implementations.Swap
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import semmle.code.cpp.models.interfaces.DataFlow
2+
import semmle.code.cpp.models.interfaces.Taint
3+
4+
/**
5+
* The standard function `swap`.
6+
*/
7+
class Swap extends DataFlowFunction {
8+
Swap() {
9+
this.hasQualifiedName("std", "swap")
10+
}
11+
12+
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
13+
(
14+
input.isInParameterPointer(0) and
15+
output.isOutParameterPointer(1)
16+
)
17+
or
18+
(
19+
input.isInParameterPointer(1) and
20+
output.isOutParameterPointer(0)
21+
)
22+
}
23+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,7 @@
171171
| taint.cpp:208:6:208:6 | 0 | taint.cpp:216:7:216:7 | y | |
172172
| taint.cpp:213:12:213:12 | ref arg x | taint.cpp:213:12:213:12 | x | |
173173
| taint.cpp:213:12:213:12 | ref arg x | taint.cpp:215:7:215:7 | x | |
174+
| taint.cpp:213:12:213:12 | x | taint.cpp:213:15:213:15 | ref arg y | |
174175
| taint.cpp:213:15:213:15 | ref arg y | taint.cpp:213:15:213:15 | y | |
175176
| taint.cpp:213:15:213:15 | ref arg y | taint.cpp:216:7:216:7 | y | |
177+
| taint.cpp:213:15:213:15 | y | taint.cpp:213:12:213:12 | ref arg x | |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,5 @@ void test_swap() {
213213
std::swap(x, y);
214214

215215
sink(x); // [FALSE POSITIVE]
216-
sink(y); // tainted [NOT DETECTED]
216+
sink(y); // tainted
217217
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
| taint.cpp:195:7:195:7 | x | taint.cpp:193:6:193:6 | x |
1717
| taint.cpp:210:7:210:7 | x | taint.cpp:207:6:207:11 | call to source |
1818
| taint.cpp:215:7:215:7 | x | taint.cpp:207:6:207:11 | call to source |
19+
| taint.cpp:216:7:216:7 | y | taint.cpp:207:6:207:11 | call to source |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
| taint.cpp:192:23:192:28 | taint.cpp:195:7:195:7 | AST only |
99
| taint.cpp:193:6:193:6 | taint.cpp:195:7:195:7 | AST only |
1010
| taint.cpp:207:6:207:11 | taint.cpp:215:7:215:7 | AST only |
11+
| taint.cpp:207:6:207:11 | taint.cpp:216:7:216:7 | AST only |

0 commit comments

Comments
 (0)