Skip to content

Commit ea9e9a7

Browse files
committed
C++: Add taint tests of std::string constructors and assignment.
1 parent 01abaf3 commit ea9e9a7

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
| file://:0:0:0:0 | p#0 | file://:0:0:0:0 | p#0 | |
44
| file://:0:0:0:0 | p#0 | file://:0:0:0:0 | p#0 | |
55
| file://:0:0:0:0 | p#0 | file://:0:0:0:0 | p#0 | |
6+
| file://:0:0:0:0 | p#0 | file://:0:0:0:0 | p#0 | |
67
| format.cpp:16:21:16:21 | s | format.cpp:22:22:22:22 | s | |
78
| format.cpp:16:31:16:31 | n | format.cpp:22:25:22:25 | n | |
89
| format.cpp:16:46:16:51 | format | format.cpp:22:28:22:33 | format | |
@@ -188,6 +189,31 @@
188189
| stl.cpp:131:15:131:24 | call to user_input | stl.cpp:131:15:131:27 | call to basic_string | TAINT |
189190
| stl.cpp:131:15:131:27 | call to basic_string | stl.cpp:132:7:132:11 | path3 | |
190191
| stl.cpp:132:7:132:11 | path3 | stl.cpp:132:13:132:17 | call to c_str | TAINT |
192+
| stl.cpp:138:18:138:24 | hello | stl.cpp:138:18:138:25 | call to basic_string | TAINT |
193+
| stl.cpp:138:18:138:25 | call to basic_string | stl.cpp:143:8:143:9 | s1 | |
194+
| stl.cpp:139:19:139:26 | call to basic_string | stl.cpp:144:8:144:9 | s2 | |
195+
| stl.cpp:139:20:139:26 | hello | stl.cpp:139:19:139:26 | call to basic_string | TAINT |
196+
| stl.cpp:141:8:141:14 | call to basic_string | stl.cpp:141:3:141:14 | ... = ... | |
197+
| stl.cpp:141:8:141:14 | call to basic_string | stl.cpp:145:8:145:9 | s3 | |
198+
| stl.cpp:141:8:141:14 | hello | stl.cpp:141:8:141:14 | call to basic_string | TAINT |
199+
| stl.cpp:149:18:149:23 | call to source | stl.cpp:149:18:149:26 | call to basic_string | TAINT |
200+
| stl.cpp:149:18:149:26 | call to basic_string | stl.cpp:154:8:154:9 | s1 | |
201+
| stl.cpp:150:19:150:27 | call to basic_string | stl.cpp:155:8:155:9 | s2 | |
202+
| stl.cpp:150:20:150:25 | call to source | stl.cpp:150:19:150:27 | call to basic_string | TAINT |
203+
| stl.cpp:152:8:152:13 | call to source | stl.cpp:152:8:152:15 | call to basic_string | TAINT |
204+
| stl.cpp:152:8:152:15 | call to basic_string | stl.cpp:152:3:152:15 | ... = ... | |
205+
| stl.cpp:152:8:152:15 | call to basic_string | stl.cpp:156:8:156:9 | s3 | |
206+
| stl.cpp:160:15:160:16 | call to basic_string | stl.cpp:161:20:161:21 | s1 | |
207+
| stl.cpp:160:15:160:16 | call to basic_string | stl.cpp:163:8:163:9 | s1 | |
208+
| stl.cpp:160:15:160:16 | call to basic_string | stl.cpp:165:8:165:9 | s1 | |
209+
| stl.cpp:161:20:161:21 | s1 | stl.cpp:166:8:166:9 | s2 | |
210+
| stl.cpp:163:8:163:9 | s1 | stl.cpp:163:3:163:9 | ... = ... | |
211+
| stl.cpp:163:8:163:9 | s1 | stl.cpp:167:8:167:9 | s3 | |
212+
| stl.cpp:171:19:171:40 | call to basic_string | stl.cpp:175:8:175:9 | s1 | |
213+
| stl.cpp:171:32:171:37 | call to source | stl.cpp:171:19:171:40 | call to basic_string | TAINT |
214+
| stl.cpp:173:8:173:28 | call to basic_string | stl.cpp:173:3:173:28 | ... = ... | |
215+
| stl.cpp:173:8:173:28 | call to basic_string | stl.cpp:176:8:176:9 | s2 | |
216+
| stl.cpp:173:20:173:25 | call to source | stl.cpp:173:8:173:28 | call to basic_string | TAINT |
191217
| swap1.cpp:14:17:14:17 | t | swap1.cpp:14:17:14:17 | t | |
192218
| swap1.cpp:14:17:14:17 | t | swap1.cpp:14:17:14:17 | t | |
193219
| swap1.cpp:14:17:14:17 | t | swap1.cpp:14:56:14:56 | t | |

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,48 @@ void test_strings2()
131131
string path3(user_input());
132132
sink(path3.c_str(), "r"); // tainted
133133
}
134+
135+
void test_string_constructors_assignments()
136+
{
137+
{
138+
std::string s1("hello");
139+
std::string s2 = "hello";
140+
std::string s3;
141+
s3 = "hello";
142+
143+
sink(s1);
144+
sink(s2);
145+
sink(s3);
146+
}
147+
148+
{
149+
std::string s1(source());
150+
std::string s2 = source();
151+
std::string s3;
152+
s3 = source();
153+
154+
sink(s1); // tainted
155+
sink(s2); // tainted
156+
sink(s3); // tainted
157+
}
158+
159+
{
160+
std::string s1;
161+
std::string s2 = s1;
162+
std::string s3;
163+
s3 = s1;
164+
165+
sink(s1);
166+
sink(s2);
167+
sink(s3);
168+
}
169+
170+
{
171+
std::string s1 = std::string(source());
172+
std::string s2;
173+
s2 = std::string(source());
174+
175+
sink(s1); // tainted
176+
sink(s2); // tainted
177+
}
178+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
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:154:8:154:9 | s1 | stl.cpp:149:18:149:23 | call to source |
20+
| stl.cpp:155:8:155:9 | s2 | stl.cpp:150:20:150:25 | call to source |
21+
| stl.cpp:156:8:156:9 | s3 | stl.cpp:152:8:152:13 | call to source |
22+
| stl.cpp:175:8:175:9 | s1 | stl.cpp:171:32:171:37 | call to source |
23+
| stl.cpp:176:8:176:9 | s2 | stl.cpp:173:20:173:25 | call to source |
1924
| swap1.cpp:60:12:60:16 | data1 | swap1.cpp:58:15:58:20 | call to source |
2025
| swap1.cpp:65:12:65:16 | data1 | swap1.cpp:58:15:58:20 | call to source |
2126
| swap1.cpp:66:12:66:16 | data1 | swap1.cpp:58:15:58:20 | call to source |

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
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:154:8:154:9 | stl.cpp:149:18:149:23 | AST only |
17+
| stl.cpp:155:8:155:9 | stl.cpp:150:20:150:25 | AST only |
18+
| stl.cpp:156:8:156:9 | stl.cpp:152:8:152:13 | AST only |
19+
| stl.cpp:175:8:175:9 | stl.cpp:171:32:171:37 | AST only |
20+
| stl.cpp:176:8:176:9 | stl.cpp:173:20:173:25 | AST only |
1621
| swap1.cpp:74:13:74:17 | swap1.cpp:69:16:69:21 | AST only |
1722
| swap1.cpp:75:13:75:17 | swap1.cpp:68:27:68:28 | AST only |
1823
| swap1.cpp:89:12:89:16 | swap1.cpp:80:23:80:23 | AST only |

0 commit comments

Comments
 (0)