Skip to content

Commit a57dfd6

Browse files
committed
C++: Taint through std::string append.
1 parent f824a89 commit a57dfd6

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,19 @@ class StdStringCStr extends TaintFunction {
1212
output.isReturnValue()
1313
}
1414
}
15+
16+
/**
17+
* The `std::string` function `append`.
18+
*/
19+
class StdStringAppend extends TaintFunction {
20+
StdStringAppend() { this.hasQualifiedName("std", "basic_string", "append") }
21+
22+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
23+
// flow from parameter to string itself (qualifier) and return value
24+
input.isParameterDeref(0) and
25+
(
26+
output.isQualifierObject() or
27+
output.isReturnValueDeref()
28+
)
29+
}
30+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,19 @@
546546
| stl.cpp:351:8:351:9 | s3 | stl.cpp:352:3:352:4 | s8 | |
547547
| stl.cpp:351:8:351:9 | s3 | stl.cpp:353:8:353:9 | s8 | |
548548
| stl.cpp:352:3:352:4 | ref arg s8 | stl.cpp:353:8:353:9 | s8 | |
549+
| stl.cpp:352:13:352:14 | s4 | stl.cpp:352:3:352:4 | ref arg s8 | TAINT |
550+
| stl.cpp:352:13:352:14 | s4 | stl.cpp:352:6:352:11 | call to append | TAINT |
549551
| stl.cpp:355:8:355:9 | s3 | stl.cpp:355:3:355:9 | ... = ... | |
550552
| stl.cpp:355:8:355:9 | s3 | stl.cpp:356:3:356:4 | s9 | |
551553
| stl.cpp:355:8:355:9 | s3 | stl.cpp:357:3:357:4 | s9 | |
552554
| stl.cpp:355:8:355:9 | s3 | stl.cpp:358:8:358:9 | s9 | |
553555
| stl.cpp:356:3:356:4 | ref arg s9 | stl.cpp:357:3:357:4 | s9 | |
554556
| stl.cpp:356:3:356:4 | ref arg s9 | stl.cpp:358:8:358:9 | s9 | |
557+
| stl.cpp:356:13:356:18 | call to source | stl.cpp:356:3:356:4 | ref arg s9 | TAINT |
558+
| stl.cpp:356:13:356:18 | call to source | stl.cpp:356:6:356:11 | call to append | TAINT |
555559
| stl.cpp:357:3:357:4 | ref arg s9 | stl.cpp:358:8:358:9 | s9 | |
560+
| stl.cpp:357:13:357:15 | | stl.cpp:357:3:357:4 | ref arg s9 | TAINT |
561+
| stl.cpp:357:13:357:15 | | stl.cpp:357:6:357:11 | call to append | TAINT |
556562
| structlikeclass.cpp:5:7:5:7 | Unknown literal | structlikeclass.cpp:5:7:5:7 | constructor init of field v | TAINT |
557563
| structlikeclass.cpp:5:7:5:7 | Unknown literal | structlikeclass.cpp:5:7:5:7 | constructor init of field v | TAINT |
558564
| structlikeclass.cpp:5:7:5:7 | this | structlikeclass.cpp:5:7:5:7 | constructor init of field v [pre-this] | |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ void test_string_append() {
350350

351351
s8 = s3;
352352
s8.append(s4);
353-
sink(s8); // tainted [NOT DETECTED]
353+
sink(s8); // tainted
354354

355355
s9 = s3;
356356
s9.append(source());
357357
s9.append(" ");
358-
sink(s9); // tainted [NOT DETECTED]
358+
sink(s9); // tainted
359359
}
360360
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
| stl.cpp:303:8:303:8 | x | stl.cpp:296:43:296:49 | source1 |
5454
| stl.cpp:311:8:311:8 | x | stl.cpp:296:43:296:49 | source1 |
5555
| stl.cpp:316:8:316:8 | x | stl.cpp:296:43:296:49 | source1 |
56+
| stl.cpp:353:8:353:9 | s8 | stl.cpp:336:18:336:23 | call to source |
57+
| stl.cpp:358:8:358:9 | s9 | stl.cpp:356:13:356:18 | call to source |
5658
| structlikeclass.cpp:35:8:35:9 | s1 | structlikeclass.cpp:29:22:29:27 | call to source |
5759
| structlikeclass.cpp:36:8:36:9 | s2 | structlikeclass.cpp:30:24:30:29 | call to source |
5860
| structlikeclass.cpp:37:8:37:9 | s3 | structlikeclass.cpp:29:22:29:27 | 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
@@ -50,6 +50,8 @@
5050
| stl.cpp:303:8:303:8 | stl.cpp:296:43:296:49 | AST only |
5151
| stl.cpp:311:8:311:8 | stl.cpp:296:43:296:49 | AST only |
5252
| stl.cpp:316:8:316:8 | stl.cpp:296:43:296:49 | AST only |
53+
| stl.cpp:353:8:353:9 | stl.cpp:336:18:336:23 | AST only |
54+
| stl.cpp:358:8:358:9 | stl.cpp:356:13:356:18 | AST only |
5355
| structlikeclass.cpp:35:8:35:9 | structlikeclass.cpp:29:22:29:27 | AST only |
5456
| structlikeclass.cpp:36:8:36:9 | structlikeclass.cpp:30:24:30:29 | AST only |
5557
| structlikeclass.cpp:37:8:37:9 | structlikeclass.cpp:29:22:29:27 | AST only |

0 commit comments

Comments
 (0)