Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a270f31

Browse files
authored
Merge pull request #11271 from jketema/ast-config-for-smart-ptrs
C++: Reintroduce the AST testing configuration for the smart pointer test too
2 parents 3d94286 + 2acda03 commit a270f31

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

cpp/ql/test/library-tests/dataflow/smart-pointers-taint/taint.ql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
import TestUtilities.dataflow.FlowTestCommon
22

3+
module AstTest {
4+
private import semmle.code.cpp.dataflow.old.TaintTracking
5+
6+
class AstSmartPointerTaintConfig extends TaintTracking::Configuration {
7+
AstSmartPointerTaintConfig() { this = "ASTSmartPointerTaintConfig" }
8+
9+
override predicate isSource(DataFlow::Node source) {
10+
source.asExpr().(FunctionCall).getTarget().getName() = "source"
11+
}
12+
13+
override predicate isSink(DataFlow::Node sink) {
14+
exists(FunctionCall call |
15+
call.getTarget().getName() = "sink" and
16+
sink.asExpr() = call.getAnArgument()
17+
)
18+
}
19+
}
20+
}
21+
322
module IRTest {
423
private import semmle.code.cpp.ir.dataflow.TaintTracking
524

cpp/ql/test/library-tests/dataflow/smart-pointers-taint/test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ void test_unique_ptr_int() {
77
std::unique_ptr<int> p1(new int(source()));
88
std::unique_ptr<int> p2 = std::make_unique<int>(source());
99

10-
sink(*p1); // $ ir
11-
sink(*p2); // $ ir=8:50
10+
sink(*p1); // $ ir MISSING: ast
11+
sink(*p2); // $ ast ir=8:50
1212
}
1313

1414
struct A {
@@ -21,26 +21,26 @@ void test_unique_ptr_struct() {
2121
std::unique_ptr<A> p1(new A{source(), 0});
2222
std::unique_ptr<A> p2 = std::make_unique<A>(source(), 0);
2323

24-
sink(p1->x); // $ ir
24+
sink(p1->x); // $ ir MISSING: ast
2525
sink(p1->y);
26-
sink(p2->x); // $ ir=22:46
26+
sink(p2->x); // $ ir=22:46 MISSING: ast
2727
sink(p2->y);
2828
}
2929

3030
void test_shared_ptr_int() {
3131
std::shared_ptr<int> p1(new int(source()));
3232
std::shared_ptr<int> p2 = std::make_shared<int>(source());
3333

34-
sink(*p1); // $ ir
35-
sink(*p2); // $ ir=32:50
34+
sink(*p1); // $ ast,ir
35+
sink(*p2); // $ ast ir=32:50
3636
}
3737

3838
void test_shared_ptr_struct() {
3939
std::shared_ptr<A> p1(new A{source(), 0});
4040
std::shared_ptr<A> p2 = std::make_shared<A>(source(), 0);
4141

42-
sink(p1->x); // $ MISSING: ir
42+
sink(p1->x); // $ MISSING: ast,ir
4343
sink(p1->y);
44-
sink(p2->x); // $ MISSING: ir
44+
sink(p2->x); // $ MISSING: ast,ir
4545
sink(p2->y);
4646
}

0 commit comments

Comments
 (0)