File tree Expand file tree Collapse file tree
src/semmle/code/cpp/models
test/library-tests/dataflow/taint-tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,4 +12,5 @@ private import implementations.Strcat
1212private import implementations.Strcpy
1313private import implementations.Strdup
1414private import implementations.Strftime
15+ private import implementations.Strings
1516private import implementations.Swap
Original file line number Diff line number Diff line change 1+ import semmle.code.cpp.models.interfaces.DataFlow
2+ import semmle.code.cpp.models.interfaces.Taint
3+
4+ /**
5+ * The `std::basic_string` constructor(s).
6+ */
7+ class StringConstructor extends DataFlowFunction {
8+ StringConstructor ( ) {
9+ this .hasQualifiedName ( "std" , "basic_string" , "basic_string" )
10+ }
11+
12+ override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
13+ // flow from any constructor argument to return value
14+ input .isInParameter ( _) and
15+ output .isOutReturnValue ( )
16+ }
17+ }
18+
19+ /**
20+ * The standard function `std::string.c_str`.
21+ */
22+ class StringCStr extends DataFlowFunction {
23+ StringCStr ( ) {
24+ this .hasQualifiedName ( "std" , "basic_string" , "c_str" )
25+ }
26+
27+ override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
28+ // flow from string itself (qualifier) to return value
29+ input .isInQualifier ( ) and
30+ output .isOutReturnValue ( )
31+ }
32+ }
Original file line number Diff line number Diff line change 106106| format.cpp:131:39:131:45 | ref arg & ... | format.cpp:132:8:132:13 | buffer | |
107107| format.cpp:131:40:131:45 | buffer | format.cpp:131:39:131:45 | & ... | |
108108| stl.cpp:67:12:67:17 | call to source | stl.cpp:71:7:71:7 | a | |
109+ | stl.cpp:68:16:68:20 | 123 | stl.cpp:68:16:68:21 | call to basic_string | |
109110| stl.cpp:68:16:68:21 | call to basic_string | stl.cpp:72:7:72:7 | b | |
110111| stl.cpp:68:16:68:21 | call to basic_string | stl.cpp:74:7:74:7 | b | |
112+ | stl.cpp:69:16:69:21 | call to source | stl.cpp:69:16:69:24 | call to basic_string | |
111113| stl.cpp:69:16:69:24 | call to basic_string | stl.cpp:73:7:73:7 | c | |
112114| stl.cpp:69:16:69:24 | call to basic_string | stl.cpp:75:7:75:7 | c | |
113115| stl.cpp:80:20:80:22 | call to basic_stringstream | stl.cpp:83:2:83:4 | ss1 | |
125127| stl.cpp:80:40:80:42 | call to basic_stringstream | stl.cpp:87:2:87:4 | ss5 | |
126128| stl.cpp:80:40:80:42 | call to basic_stringstream | stl.cpp:93:7:93:9 | ss5 | |
127129| stl.cpp:80:40:80:42 | call to basic_stringstream | stl.cpp:98:7:98:9 | ss5 | |
130+ | stl.cpp:81:16:81:21 | call to source | stl.cpp:81:16:81:24 | call to basic_string | |
128131| stl.cpp:81:16:81:24 | call to basic_string | stl.cpp:87:9:87:9 | t | |
129132| stl.cpp:83:2:83:4 | ref arg ss1 | stl.cpp:89:7:89:9 | ss1 | |
130133| stl.cpp:83:2:83:4 | ref arg ss1 | stl.cpp:94:7:94:9 | ss1 | |
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ void test_string()
7070
7171 sink (a); // tainted
7272 sink (b);
73- sink (c); // tainted [NOT DETECTED]
73+ sink (c); // tainted
7474 sink (b.c_str ());
7575 sink (c.c_str ()); // tainted [NOT DETECTED]
7676}
Original file line number Diff line number Diff line change 99| format.cpp:101:8:101:13 | buffer | format.cpp:100:31:100:45 | call to source |
1010| format.cpp:106:8:106:14 | wbuffer | format.cpp:105:38:105:52 | call to source |
1111| stl.cpp:71:7:71:7 | a | stl.cpp:67:12:67:17 | call to source |
12+ | stl.cpp:73:7:73:7 | c | stl.cpp:69:16:69:21 | call to source |
1213| taint.cpp:8:8:8:13 | clean1 | taint.cpp:4:27:4:33 | source1 |
1314| taint.cpp:16:8:16:14 | source1 | taint.cpp:12:22:12:27 | call to source |
1415| taint.cpp:17:8:17:16 | ++ ... | taint.cpp:12:22:12:27 | call to source |
Original file line number Diff line number Diff line change 88| format.cpp:96:8:96:13 | format.cpp:95:30:95:43 | AST only |
99| format.cpp:101:8:101:13 | format.cpp:100:31:100:45 | AST only |
1010| format.cpp:106:8:106:14 | format.cpp:105:38:105:52 | AST only |
11+ | stl.cpp:73:7:73:7 | stl.cpp:69:16:69:21 | AST only |
1112| taint.cpp:41:7:41:13 | taint.cpp:35:12:35:17 | AST only |
1213| taint.cpp:42:7:42:13 | taint.cpp:35:12:35:17 | AST only |
1314| taint.cpp:43:7:43:13 | taint.cpp:37:22:37:27 | AST only |
You can’t perform that action at this time.
0 commit comments