Skip to content

Commit f62ad75

Browse files
committed
C++: Taint through std::string operator+=.
1 parent cf6f530 commit f62ad75

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-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
@@ -40,10 +40,13 @@ class StdStringPlus extends TaintFunction {
4040
}
4141

4242
/**
43-
* The `std::string` function `append`.
43+
* The `std::string` functions `operator+=` and `append`.
4444
*/
4545
class StdStringAppend extends TaintFunction {
46-
StdStringAppend() { this.hasQualifiedName("std", "basic_string", "append") }
46+
StdStringAppend() {
47+
this.hasQualifiedName("std", "basic_string", "operator+=") or
48+
this.hasQualifiedName("std", "basic_string", "append")
49+
}
4750

4851
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
4952
// flow from parameter to string itself (qualifier) and return value

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,19 @@
549549
| stl.cpp:342:8:342:9 | s3 | stl.cpp:343:3:343:4 | s6 | |
550550
| stl.cpp:342:8:342:9 | s3 | stl.cpp:344:8:344:9 | s6 | |
551551
| stl.cpp:343:3:343:4 | ref arg s6 | stl.cpp:344:8:344:9 | s6 | |
552+
| stl.cpp:343:9:343:10 | s4 | stl.cpp:343:3:343:4 | ref arg s6 | TAINT |
553+
| stl.cpp:343:9:343:10 | s4 | stl.cpp:343:6:343:6 | call to operator+= | TAINT |
552554
| stl.cpp:346:8:346:9 | s3 | stl.cpp:346:3:346:9 | ... = ... | |
553555
| stl.cpp:346:8:346:9 | s3 | stl.cpp:347:3:347:4 | s7 | |
554556
| stl.cpp:346:8:346:9 | s3 | stl.cpp:348:3:348:4 | s7 | |
555557
| stl.cpp:346:8:346:9 | s3 | stl.cpp:349:8:349:9 | s7 | |
556558
| stl.cpp:347:3:347:4 | ref arg s7 | stl.cpp:348:3:348:4 | s7 | |
557559
| stl.cpp:347:3:347:4 | ref arg s7 | stl.cpp:349:8:349:9 | s7 | |
560+
| stl.cpp:347:9:347:14 | call to source | stl.cpp:347:3:347:4 | ref arg s7 | TAINT |
561+
| stl.cpp:347:9:347:14 | call to source | stl.cpp:347:6:347:6 | call to operator+= | TAINT |
558562
| stl.cpp:348:3:348:4 | ref arg s7 | stl.cpp:349:8:349:9 | s7 | |
563+
| stl.cpp:348:9:348:11 | | stl.cpp:348:3:348:4 | ref arg s7 | TAINT |
564+
| stl.cpp:348:9:348:11 | | stl.cpp:348:6:348:6 | call to operator+= | TAINT |
559565
| stl.cpp:351:8:351:9 | s3 | stl.cpp:351:3:351:9 | ... = ... | |
560566
| stl.cpp:351:8:351:9 | s3 | stl.cpp:352:3:352:4 | s8 | |
561567
| stl.cpp:351:8:351:9 | s3 | stl.cpp:353:8:353:9 | s8 | |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,12 @@ void test_string_append() {
341341

342342
s6 = s3;
343343
s6 += s4;
344-
sink(s6); // tainted [NOT DETECTED]
344+
sink(s6); // tainted
345345

346346
s7 = s3;
347347
s7 += source();
348348
s7 += " ";
349-
sink(s7); // tainted [NOT DETECTED]
349+
sink(s7); // tainted
350350

351351
s8 = s3;
352352
s8.append(s4);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
| stl.cpp:328:11:328:11 | call to operator+ | stl.cpp:323:18:323:23 | call to source |
5959
| stl.cpp:331:11:331:11 | call to operator+ | stl.cpp:331:13:331:18 | call to source |
6060
| stl.cpp:340:8:340:9 | s5 | stl.cpp:336:18:336:23 | call to source |
61+
| stl.cpp:344:8:344:9 | s6 | stl.cpp:336:18:336:23 | call to source |
62+
| stl.cpp:349:8:349:9 | s7 | stl.cpp:347:9:347:14 | call to source |
6163
| stl.cpp:353:8:353:9 | s8 | stl.cpp:336:18:336:23 | call to source |
6264
| stl.cpp:358:8:358:9 | s9 | stl.cpp:356:13:356:18 | call to source |
6365
| structlikeclass.cpp:35:8:35:9 | s1 | 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
@@ -55,6 +55,8 @@
5555
| stl.cpp:328:11:328:11 | stl.cpp:323:18:323:23 | AST only |
5656
| stl.cpp:331:11:331:11 | stl.cpp:331:13:331:18 | AST only |
5757
| stl.cpp:340:8:340:9 | stl.cpp:336:18:336:23 | AST only |
58+
| stl.cpp:344:8:344:9 | stl.cpp:336:18:336:23 | AST only |
59+
| stl.cpp:349:8:349:9 | stl.cpp:347:9:347:14 | AST only |
5860
| stl.cpp:353:8:353:9 | stl.cpp:336:18:336:23 | AST only |
5961
| stl.cpp:358:8:358:9 | stl.cpp:356:13:356:18 | AST only |
6062
| structlikeclass.cpp:35:8:35:9 | structlikeclass.cpp:29:22:29:27 | AST only |

0 commit comments

Comments
 (0)