Skip to content

Commit 23d3109

Browse files
committed
C++: Use taintedWithPath in more tests. This is the predicate that's currently hooked up to the new IR taint tracking library.
1 parent 6ba35f4 commit 23d3109

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/annotate_path_to_sink/tainted.ql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import cpp
77
import semmle.code.cpp.security.TaintTrackingImpl as ASTTaintTracking
88
import semmle.code.cpp.ir.dataflow.DefaultTaintTracking as IRDefaultTaintTracking
9+
import IRDefaultTaintTracking::TaintedWithPath as TaintedWithPath
910
import TestUtilities.InlineExpectationsTest
1011

1112
predicate isSink(Element sink) {
@@ -17,7 +18,13 @@ predicate isSink(Element sink) {
1718

1819
predicate astTaint(Expr source, Element sink) { ASTTaintTracking::tainted(source, sink) }
1920

20-
predicate irTaint(Expr source, Element sink) { IRDefaultTaintTracking::tainted(source, sink) }
21+
class SourceConfiguration extends TaintedWithPath::TaintTrackingConfiguration {
22+
override predicate isSink(Element e) { any() }
23+
}
24+
25+
predicate irTaint(Expr source, Element sink) {
26+
TaintedWithPath::taintedWithPath(source, sink, _, _)
27+
}
2128

2229
class IRDefaultTaintTrackingTest extends InlineExpectationsTest {
2330
IRDefaultTaintTrackingTest() { this = "IRDefaultTaintTrackingTest" }

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/annotate_sinks_only/defaulttainttracking.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ int main() {
1313

1414

1515

16-
sink(_strdup(getenv("VAR"))); // $ ir MISSING: ast
17-
sink(strdup(getenv("VAR"))); // $ ast,ir
16+
sink(_strdup(getenv("VAR"))); // $ MISSING: ast,ir
17+
sink(strdup(getenv("VAR"))); // $ ast MISSING: ir
1818
sink(unmodeled_function(getenv("VAR"))); // clean by assumption
1919

2020
char untainted_buf[100] = "";
@@ -250,12 +250,12 @@ void sink(iovec);
250250
int test_readv_and_writev(iovec* iovs) {
251251
readv(0, iovs, 16);
252252
sink(iovs); // $ast,ir
253-
sink(iovs[0]); // $ast MISSING: ir
254-
sink(*iovs); // $ast MISSING: ir
253+
sink(iovs[0]); // $ast,ir
254+
sink(*iovs); // $ast,ir
255255

256256
char* p = (char*)iovs[1].iov_base;
257-
sink(p); // $ MISSING: ast,ir
258-
sink(*p); // $ MISSING: ast,ir
257+
sink(p); // $ ir MISSING: ast
258+
sink(*p); // $ ir MISSING: ast
259259

260260
writev(0, iovs, 16); // $ remote
261261
}

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/annotate_sinks_only/stl.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void test_string()
7373
sink(b); // clean
7474
sink(c); // $ ir MISSING: ast
7575
sink(b.c_str()); // clean
76-
sink(c.c_str()); // $ MISSING: ast,ir
76+
sink(c.c_str()); // $ ir MISSING: ast
7777
}
7878

7979
void test_stringstream()
@@ -91,11 +91,11 @@ void test_stringstream()
9191
sink(ss2); // $ ir MISSING: ast
9292
sink(ss3); // $ MISSING: ast,ir
9393
sink(ss4); // $ ir MISSING: ast
94-
sink(ss5); // $ ir MISSING: ast
94+
sink(ss5); // $ MISSING: ast,ir
9595
sink(ss1.str());
96-
sink(ss2.str()); // $ MISSING: ast,ir
96+
sink(ss2.str()); // $ ir MISSING: ast
9797
sink(ss3.str()); // $ MISSING: ast,ir
98-
sink(ss4.str()); // $ MISSING: ast,ir
98+
sink(ss4.str()); // $ ir MISSING: ast
9999
sink(ss5.str()); // $ MISSING: ast,ir
100100
}
101101

@@ -123,14 +123,14 @@ void sink(const char *filename, const char *mode);
123123
void test_strings2()
124124
{
125125
string path1 = user_input();
126-
sink(path1.c_str(), "r"); // $ MISSING: ast,ir
126+
sink(path1.c_str(), "r"); // $ ir MISSING: ast
127127

128128
string path2;
129129
path2 = user_input();
130-
sink(path2.c_str(), "r"); // $ MISSING: ast,ir
130+
sink(path2.c_str(), "r"); // $ ir MISSING: ast
131131

132132
string path3(user_input());
133-
sink(path3.c_str(), "r"); // $ MISSING: ast,ir
133+
sink(path3.c_str(), "r"); // $ ir MISSING: ast
134134
}
135135

136136
void test_string3()
@@ -154,6 +154,6 @@ void test_string4()
154154
// convert back std::string -> char *
155155
cs = ss.c_str();
156156

157-
sink(cs); // $ ast MISSING: ir
157+
sink(cs); // $ ast,ir
158158
sink(ss); // $ ir MISSING: ast
159159
}

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/annotate_sinks_only/tainted.ql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,26 @@
77
import cpp
88
import semmle.code.cpp.security.TaintTrackingImpl as ASTTaintTracking
99
import semmle.code.cpp.ir.dataflow.DefaultTaintTracking as IRDefaultTaintTracking
10+
import IRDefaultTaintTracking::TaintedWithPath as TaintedWithPath
1011
import TestUtilities.InlineExpectationsTest
1112

12-
predicate isSink(Element sink) {
13+
predicate argToSinkCall(Element sink) {
1314
exists(FunctionCall call |
1415
call.getTarget().getName() = "sink" and
1516
sink = call.getAnArgument()
1617
)
1718
}
1819

1920
predicate astTaint(Expr source, Element sink) {
20-
ASTTaintTracking::tainted(source, sink) and isSink(sink)
21+
ASTTaintTracking::tainted(source, sink) and argToSinkCall(sink)
22+
}
23+
24+
class SourceConfiguration extends TaintedWithPath::TaintTrackingConfiguration {
25+
override predicate isSink(Element e) { argToSinkCall(e) }
2126
}
2227

2328
predicate irTaint(Expr source, Element sink) {
24-
IRDefaultTaintTracking::tainted(source, sink) and isSink(sink)
29+
TaintedWithPath::taintedWithPath(source, sink, _, _)
2530
}
2631

2732
class IRDefaultTaintTrackingTest extends InlineExpectationsTest {

0 commit comments

Comments
 (0)