Skip to content

Commit 2f192f6

Browse files
committed
C++: Add a test of char* -> std::string -> char* taint.
1 parent 1b8f3c4 commit 2f192f6

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@
188188
| stl.cpp:131:15:131:24 | call to user_input | stl.cpp:131:15:131:27 | call to basic_string | TAINT |
189189
| stl.cpp:131:15:131:27 | call to basic_string | stl.cpp:132:7:132:11 | path3 | |
190190
| stl.cpp:132:7:132:11 | path3 | stl.cpp:132:13:132:17 | call to c_str | TAINT |
191+
| stl.cpp:137:19:137:24 | call to source | stl.cpp:140:17:140:18 | cs | |
192+
| stl.cpp:137:19:137:24 | call to source | stl.cpp:142:7:142:8 | cs | |
193+
| stl.cpp:140:17:140:18 | cs | stl.cpp:140:17:140:19 | call to basic_string | TAINT |
194+
| stl.cpp:140:17:140:19 | call to basic_string | stl.cpp:143:7:143:8 | ss | |
195+
| stl.cpp:148:19:148:24 | call to source | stl.cpp:151:17:151:18 | cs | |
196+
| stl.cpp:151:17:151:18 | cs | stl.cpp:151:17:151:19 | call to basic_string | TAINT |
197+
| stl.cpp:151:17:151:19 | call to basic_string | stl.cpp:154:7:154:8 | ss | |
198+
| stl.cpp:151:17:151:19 | call to basic_string | stl.cpp:157:7:157:8 | ss | |
199+
| stl.cpp:154:7:154:8 | ss | stl.cpp:154:10:154:14 | call to c_str | TAINT |
200+
| stl.cpp:154:10:154:14 | call to c_str | stl.cpp:154:2:154:16 | ... = ... | |
201+
| stl.cpp:154:10:154:14 | call to c_str | stl.cpp:156:7:156:8 | cs | |
191202
| taint.cpp:4:27:4:33 | source1 | taint.cpp:6:13:6:19 | source1 | |
192203
| taint.cpp:4:40:4:45 | clean1 | taint.cpp:5:8:5:13 | clean1 | |
193204
| taint.cpp:4:40:4:45 | clean1 | taint.cpp:6:3:6:8 | clean1 | |

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,28 @@ void test_strings2()
131131
string path3(user_input());
132132
sink(path3.c_str(), "r"); // tainted
133133
}
134+
135+
void test_string3()
136+
{
137+
const char *cs = source();
138+
139+
// convert char * -> std::string
140+
std::string ss(cs);
141+
142+
sink(cs); // tainted
143+
sink(ss); // tainted
144+
}
145+
146+
void test_string4()
147+
{
148+
const char *cs = source();
149+
150+
// convert char * -> std::string
151+
std::string ss(cs);
152+
153+
// convert back std::string -> char *
154+
cs = ss.c_str();
155+
156+
sink(cs); // tainted
157+
sink(ss); // tainted
158+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
| stl.cpp:125:13:125:17 | call to c_str | stl.cpp:117:10:117:15 | call to source |
1717
| stl.cpp:129:13:129:17 | call to c_str | stl.cpp:117:10:117:15 | call to source |
1818
| stl.cpp:132:13:132:17 | call to c_str | stl.cpp:117:10:117:15 | call to source |
19+
| stl.cpp:142:7:142:8 | cs | stl.cpp:137:19:137:24 | call to source |
20+
| stl.cpp:143:7:143:8 | ss | stl.cpp:137:19:137:24 | call to source |
21+
| stl.cpp:156:7:156:8 | cs | stl.cpp:148:19:148:24 | call to source |
22+
| stl.cpp:157:7:157:8 | ss | stl.cpp:148:19:148:24 | call to source |
1923
| taint.cpp:8:8:8:13 | clean1 | taint.cpp:4:27:4:33 | source1 |
2024
| taint.cpp:16:8:16:14 | source1 | taint.cpp:12:22:12:27 | call to source |
2125
| taint.cpp:17:8:17:16 | ++ ... | taint.cpp:12:22:12:27 | call to source |

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
| stl.cpp:125:13:125:17 | stl.cpp:117:10:117:15 | AST only |
1414
| stl.cpp:129:13:129:17 | stl.cpp:117:10:117:15 | AST only |
1515
| stl.cpp:132:13:132:17 | stl.cpp:117:10:117:15 | AST only |
16+
| stl.cpp:142:7:142:8 | stl.cpp:137:19:137:26 | IR only |
17+
| stl.cpp:143:7:143:8 | stl.cpp:137:19:137:24 | AST only |
18+
| stl.cpp:156:7:156:8 | stl.cpp:148:19:148:24 | AST only |
19+
| stl.cpp:157:7:157:8 | stl.cpp:148:19:148:24 | AST only |
1620
| taint.cpp:41:7:41:13 | taint.cpp:35:12:35:17 | AST only |
1721
| taint.cpp:42:7:42:13 | taint.cpp:35:12:35:17 | AST only |
1822
| taint.cpp:43:7:43:13 | taint.cpp:37:22:37:27 | AST only |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
| format.cpp:158:7:158:27 | ... + ... | format.cpp:148:16:148:30 | call to source |
44
| stl.cpp:71:7:71:7 | (const char *)... | stl.cpp:67:12:67:17 | call to source |
55
| stl.cpp:71:7:71:7 | a | stl.cpp:67:12:67:17 | call to source |
6+
| stl.cpp:142:7:142:8 | cs | stl.cpp:137:19:137:24 | call to source |
7+
| stl.cpp:142:7:142:8 | cs | stl.cpp:137:19:137:26 | (const char *)... |
68
| taint.cpp:8:8:8:13 | clean1 | taint.cpp:4:27:4:33 | source1 |
79
| taint.cpp:16:8:16:14 | source1 | taint.cpp:12:22:12:27 | call to source |
810
| taint.cpp:17:8:17:16 | ++ ... | taint.cpp:12:22:12:27 | call to source |

0 commit comments

Comments
 (0)