Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a3d418

Browse files
committed
C++: Change some of the taint flows to data flows.
1 parent 8a143be commit 5a3d418

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,15 @@ class StdBasicOStream extends TemplateClass {
298298
/**
299299
* The `std::ostream` function `operator<<` (defined as a member function).
300300
*/
301-
class StdOStreamOut extends TaintFunction {
301+
class StdOStreamOut extends DataFlowFunction, TaintFunction {
302302
StdOStreamOut() { this.hasQualifiedName("std", "basic_ostream", "operator<<") }
303303

304+
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
305+
// flow from qualifier to return value
306+
input.isQualifierObject() and
307+
output.isReturnValueDeref()
308+
}
309+
304310
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
305311
// flow from parameter to qualifier
306312
input.isParameter(0) and
@@ -310,10 +316,6 @@ class StdOStreamOut extends TaintFunction {
310316
input.isParameter(0) and
311317
output.isReturnValueDeref()
312318
or
313-
// flow from qualifier to return value
314-
input.isQualifierObject() and
315-
output.isReturnValueDeref()
316-
or
317319
// reverse flow from returned reference to the qualifier
318320
input.isReturnValueDeref() and
319321
output.isQualifierObject()
@@ -323,13 +325,19 @@ class StdOStreamOut extends TaintFunction {
323325
/**
324326
* The `std::ostream` function `operator<<` (defined as a non-member function).
325327
*/
326-
class StdOStreamOutNonMember extends TaintFunction {
328+
class StdOStreamOutNonMember extends DataFlowFunction, TaintFunction {
327329
StdOStreamOutNonMember() {
328330
this.hasQualifiedName("std", "operator<<") and
329331
this.getUnspecifiedType().(ReferenceType).getBaseType() =
330332
any(StdBasicOStream s).getAnInstantiation()
331333
}
332334

335+
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
336+
// flow from first parameter to return value
337+
input.isParameter(0) and
338+
output.isReturnValueDeref()
339+
}
340+
333341
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
334342
// flow from second parameter to first parameter
335343
input.isParameter(1) and
@@ -339,10 +347,6 @@ class StdOStreamOutNonMember extends TaintFunction {
339347
input.isParameter(1) and
340348
output.isReturnValueDeref()
341349
or
342-
// flow from first parameter to return value
343-
input.isParameter(0) and
344-
output.isReturnValueDeref()
345-
or
346350
// reverse flow from returned reference to the first parameter
347351
input.isReturnValueDeref() and
348352
output.isParameterDeref(0)

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,13 +1457,11 @@
14571457
| stringstream.cpp:75:7:75:9 | ref arg ss1 | stringstream.cpp:77:7:77:9 | ss1 | |
14581458
| stringstream.cpp:75:7:75:9 | ref arg ss1 | stringstream.cpp:80:7:80:9 | ss1 | |
14591459
| stringstream.cpp:75:7:75:9 | ref arg ss1 | stringstream.cpp:82:7:82:9 | ss1 | |
1460-
| stringstream.cpp:75:7:75:9 | ss1 | stringstream.cpp:75:11:75:11 | call to operator<< | TAINT |
14611460
| stringstream.cpp:75:14:75:17 | 1234 | stringstream.cpp:75:7:75:9 | ref arg ss1 | TAINT |
14621461
| stringstream.cpp:75:14:75:17 | 1234 | stringstream.cpp:75:11:75:11 | call to operator<< | TAINT |
14631462
| stringstream.cpp:76:7:76:9 | ref arg ss2 | stringstream.cpp:78:7:78:9 | ss2 | |
14641463
| stringstream.cpp:76:7:76:9 | ref arg ss2 | stringstream.cpp:81:7:81:9 | ss2 | |
14651464
| stringstream.cpp:76:7:76:9 | ref arg ss2 | stringstream.cpp:83:7:83:9 | ss2 | |
1466-
| stringstream.cpp:76:7:76:9 | ss2 | stringstream.cpp:76:11:76:11 | call to operator<< | TAINT |
14671465
| stringstream.cpp:76:14:76:19 | source | stringstream.cpp:76:7:76:9 | ref arg ss2 | TAINT |
14681466
| stringstream.cpp:76:14:76:19 | source | stringstream.cpp:76:11:76:11 | call to operator<< | TAINT |
14691467
| stringstream.cpp:77:7:77:9 | ref arg ss1 | stringstream.cpp:80:7:80:9 | ss1 | |

0 commit comments

Comments
 (0)