Skip to content

Commit f132bca

Browse files
committed
CPP: Add a taint flow test of 'std::swap'.
1 parent a6b7f2d commit f132bca

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,15 @@
161161
| taint.cpp:194:10:194:10 | x | taint.cpp:194:9:194:10 | & ... | TAINT |
162162
| taint.cpp:194:13:194:18 | source | taint.cpp:194:9:194:10 | ref arg & ... | TAINT |
163163
| taint.cpp:194:21:194:31 | sizeof(int) | taint.cpp:194:9:194:10 | ref arg & ... | TAINT |
164+
| taint.cpp:207:6:207:11 | call to source | taint.cpp:207:2:207:13 | ... = ... | |
165+
| taint.cpp:207:6:207:11 | call to source | taint.cpp:210:7:210:7 | x | |
166+
| taint.cpp:207:6:207:11 | call to source | taint.cpp:213:12:213:12 | x | |
167+
| taint.cpp:207:6:207:11 | call to source | taint.cpp:215:7:215:7 | x | |
168+
| taint.cpp:208:6:208:6 | 0 | taint.cpp:208:2:208:6 | ... = ... | |
169+
| taint.cpp:208:6:208:6 | 0 | taint.cpp:211:7:211:7 | y | |
170+
| taint.cpp:208:6:208:6 | 0 | taint.cpp:213:15:213:15 | y | |
171+
| taint.cpp:208:6:208:6 | 0 | taint.cpp:216:7:216:7 | y | |
172+
| taint.cpp:213:12:213:12 | ref arg x | taint.cpp:213:12:213:12 | x | |
173+
| taint.cpp:213:12:213:12 | ref arg x | taint.cpp:215:7:215:7 | x | |
174+
| taint.cpp:213:15:213:15 | ref arg y | taint.cpp:213:15:213:15 | y | |
175+
| taint.cpp:213:15:213:15 | ref arg y | taint.cpp:216:7:216:7 | y | |

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,24 @@ void test_memcpy(int *source) {
194194
memcpy(&x, source, sizeof(int));
195195
sink(x);
196196
}
197+
198+
// --- swap ---
199+
200+
namespace std {
201+
template<class T> constexpr void swap(T& a, T& b);
202+
}
203+
204+
void test_swap() {
205+
int x, y;
206+
207+
x = source();
208+
y = 0;
209+
210+
sink(x); // tainted
211+
sink(y);
212+
213+
std::swap(x, y);
214+
215+
sink(x); // [FALSE POSITIVE]
216+
sink(y); // tainted [NOT DETECTED]
217+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
| taint.cpp:181:8:181:9 | * ... | taint.cpp:185:11:185:16 | call to source |
1515
| taint.cpp:195:7:195:7 | x | taint.cpp:192:23:192:28 | source |
1616
| taint.cpp:195:7:195:7 | x | taint.cpp:193:6:193:6 | x |
17+
| taint.cpp:210:7:210:7 | x | taint.cpp:207:6:207:11 | call to source |
18+
| taint.cpp:215:7:215:7 | x | 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
@@ -7,3 +7,4 @@
77
| taint.cpp:185:11:185:16 | taint.cpp:181:8:181:9 | AST only |
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 |
10+
| taint.cpp:207:6:207:11 | taint.cpp:215:7:215:7 | AST only |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
| taint.cpp:151:7:151:12 | Call: call to select | taint.cpp:151:20:151:25 | Call: call to source |
88
| taint.cpp:167:8:167:13 | Call: call to source | taint.cpp:167:8:167:13 | Call: call to source |
99
| taint.cpp:168:8:168:14 | Load: tainted | taint.cpp:164:19:164:24 | Call: call to source |
10+
| taint.cpp:210:7:210:7 | Load: x | taint.cpp:207:6:207:11 | Call: call to source |

0 commit comments

Comments
 (0)