Skip to content

Commit c4de071

Browse files
committed
C++: Flow through swap.
1 parent eb7bd6e commit c4de071

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,13 @@ class StdStringSubstr extends TaintFunction {
256256
}
257257

258258
/**
259-
* The standard function `std::string.swap`.
259+
* The standard functions `std::string.swap` and `std::stringstream::swap`.
260260
*/
261261
class StdStringSwap extends TaintFunction {
262-
StdStringSwap() { this.hasQualifiedName("std", "basic_string", "swap") }
262+
StdStringSwap() {
263+
this.hasQualifiedName("std", "basic_string", "swap") or
264+
this.hasQualifiedName("std", "basic_stringstream", "swap")
265+
}
263266

264267
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
265268
// str1.swap(str2)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,9 +1623,13 @@
16231623
| stringstream.cpp:115:24:115:32 | call to basic_stringstream | stringstream.cpp:118:2:118:4 | ss4 | |
16241624
| stringstream.cpp:115:24:115:32 | call to basic_stringstream | stringstream.cpp:123:7:123:9 | ss4 | |
16251625
| stringstream.cpp:117:2:117:4 | ref arg ss1 | stringstream.cpp:120:7:120:9 | ss1 | |
1626+
| stringstream.cpp:117:2:117:4 | ss1 | stringstream.cpp:117:11:117:13 | ref arg ss2 | TAINT |
16261627
| stringstream.cpp:117:11:117:13 | ref arg ss2 | stringstream.cpp:121:7:121:9 | ss2 | |
1628+
| stringstream.cpp:117:11:117:13 | ss2 | stringstream.cpp:117:2:117:4 | ref arg ss1 | TAINT |
16271629
| stringstream.cpp:118:2:118:4 | ref arg ss4 | stringstream.cpp:123:7:123:9 | ss4 | |
1630+
| stringstream.cpp:118:2:118:4 | ss4 | stringstream.cpp:118:11:118:13 | ref arg ss3 | TAINT |
16281631
| stringstream.cpp:118:11:118:13 | ref arg ss3 | stringstream.cpp:122:7:122:9 | ss3 | |
1632+
| stringstream.cpp:118:11:118:13 | ss3 | stringstream.cpp:118:2:118:4 | ref arg ss4 | TAINT |
16291633
| stringstream.cpp:128:20:128:22 | call to basic_stringstream | stringstream.cpp:142:7:142:9 | ss1 | |
16301634
| stringstream.cpp:128:20:128:22 | call to basic_stringstream | stringstream.cpp:145:7:145:9 | ss1 | |
16311635
| stringstream.cpp:128:20:128:22 | call to basic_stringstream | stringstream.cpp:153:7:153:9 | ss1 | |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ void test_stringstream_swap()
117117
ss1.swap(ss2);
118118
ss4.swap(ss3);
119119

120-
sink(ss1); // tainted [NOT DETECTED]
120+
sink(ss1); // tainted
121121
sink(ss2); // [FALSE POSITIVE]
122-
sink(ss3); // tainted [NOT DETECTED]
122+
sink(ss3); // tainted
123123
sink(ss4); // [FALSE POSITIVE]
124124
}
125125

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@
196196
| stringstream.cpp:103:7:103:9 | ss2 | stringstream.cpp:91:19:91:24 | call to source |
197197
| stringstream.cpp:105:7:105:9 | ss4 | stringstream.cpp:95:44:95:49 | call to source |
198198
| stringstream.cpp:107:7:107:9 | ss6 | stringstream.cpp:100:31:100:36 | call to source |
199+
| stringstream.cpp:120:7:120:9 | ss1 | stringstream.cpp:113:24:113:29 | call to source |
199200
| stringstream.cpp:121:7:121:9 | ss2 | stringstream.cpp:113:24:113:29 | call to source |
201+
| stringstream.cpp:122:7:122:9 | ss3 | stringstream.cpp:115:24:115:29 | call to source |
200202
| stringstream.cpp:123:7:123:9 | ss4 | stringstream.cpp:115:24:115:29 | call to source |
201203
| stringstream.cpp:143:11:143:11 | call to operator<< | stringstream.cpp:143:14:143:19 | call to source |
202204
| stringstream.cpp:146:11:146:11 | call to operator>> | stringstream.cpp:143:14:143:19 | 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
@@ -196,7 +196,9 @@
196196
| stringstream.cpp:103:7:103:9 | stringstream.cpp:91:19:91:24 | AST only |
197197
| stringstream.cpp:105:7:105:9 | stringstream.cpp:95:44:95:49 | AST only |
198198
| stringstream.cpp:107:7:107:9 | stringstream.cpp:100:31:100:36 | AST only |
199+
| stringstream.cpp:120:7:120:9 | stringstream.cpp:113:24:113:29 | AST only |
199200
| stringstream.cpp:121:7:121:9 | stringstream.cpp:113:24:113:29 | AST only |
201+
| stringstream.cpp:122:7:122:9 | stringstream.cpp:115:24:115:29 | AST only |
200202
| stringstream.cpp:123:7:123:9 | stringstream.cpp:115:24:115:29 | AST only |
201203
| stringstream.cpp:143:11:143:11 | stringstream.cpp:143:14:143:21 | IR only |
202204
| stringstream.cpp:143:11:143:22 | stringstream.cpp:143:14:143:19 | IR only |

0 commit comments

Comments
 (0)