-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor tests which
extends Configuration
- Loading branch information
1 parent
66f971e
commit 49521f6
Showing
7 changed files
with
65 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
import java | ||
import semmle.code.java.dataflow.DataFlow | ||
import DataFlow | ||
|
||
StringLiteral src() { result.getCompilationUnit().fromSource() } | ||
|
||
class Conf extends Configuration { | ||
Conf() { this = "qq capture" } | ||
module Config implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node n) { n.asExpr() = src() } | ||
|
||
override predicate isSource(Node n) { n.asExpr() = src() } | ||
|
||
override predicate isSink(Node n) { any() } | ||
predicate isSink(DataFlow::Node n) { any() } | ||
} | ||
|
||
from Node src, Node sink, Conf conf | ||
where conf.hasFlow(src, sink) | ||
module Flow = DataFlow::Global<Config>; | ||
|
||
from DataFlow::Node src, DataFlow::Node sink | ||
where Flow::flow(src, sink) | ||
select src, sink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import java | ||
import semmle.code.java.dataflow.DataFlow | ||
import DataFlow | ||
|
||
class Conf extends Configuration { | ||
Conf() { this = "qqconf" } | ||
module Config implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node n) { n.asExpr().(MethodAccess).getMethod().hasName("source") } | ||
|
||
override predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("source") } | ||
|
||
override predicate isSink(Node n) { n.asExpr().(Argument).getCall().getCallee().hasName("sink") } | ||
predicate isSink(DataFlow::Node n) { n.asExpr().(Argument).getCall().getCallee().hasName("sink") } | ||
} | ||
|
||
from Conf conf, Node src, Node sink | ||
where conf.hasFlow(src, sink) | ||
module Flow = DataFlow::Global<Config>; | ||
|
||
from DataFlow::Node src, DataFlow::Node sink | ||
where Flow::flow(src, sink) | ||
select src, sink |
15 changes: 7 additions & 8 deletions
15
java/ql/test/library-tests/dataflow/switchexpr/switchexprflow.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import java | ||
import semmle.code.java.dataflow.DataFlow | ||
import DataFlow | ||
|
||
class Conf extends Configuration { | ||
Conf() { this = "qqconf" } | ||
module Config implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node n) { n.asExpr().(MethodAccess).getMethod().hasName("source") } | ||
|
||
override predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("source") } | ||
|
||
override predicate isSink(Node n) { any() } | ||
predicate isSink(DataFlow::Node n) { any() } | ||
} | ||
|
||
from Conf c, Node sink | ||
where c.hasFlow(_, sink) | ||
module Flow = DataFlow::Global<Config>; | ||
|
||
from DataFlow::Node sink | ||
where Flow::flowTo(sink) | ||
select sink |
17 changes: 8 additions & 9 deletions
17
java/ql/test/library-tests/dataflow/taintgettersetter/taintgettersetter.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
import java | ||
import semmle.code.java.dataflow.DataFlow | ||
import DataFlow | ||
|
||
class Conf extends Configuration { | ||
Conf() { this = "taintgettersetter" } | ||
module Config implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node n) { n.asExpr().(MethodAccess).getMethod().hasName("taint") } | ||
|
||
override predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("taint") } | ||
|
||
override predicate isSink(Node n) { | ||
predicate isSink(DataFlow::Node n) { | ||
exists(MethodAccess sink | | ||
sink.getAnArgument() = n.asExpr() and sink.getMethod().hasName("sink") | ||
) | ||
} | ||
|
||
override predicate isAdditionalFlowStep(Node n1, Node n2) { | ||
predicate isAdditionalFlowStep(DataFlow::Node n1, DataFlow::Node n2) { | ||
exists(AddExpr add | | ||
add.getType() instanceof TypeString and add.getAnOperand() = n1.asExpr() and n2.asExpr() = add | ||
) | ||
} | ||
} | ||
|
||
from Node src, Node sink, Conf conf | ||
where conf.hasFlow(src, sink) | ||
module Flow = DataFlow::Global<Config>; | ||
|
||
from DataFlow::Node src, DataFlow::Node sink | ||
where Flow::flow(src, sink) | ||
select src, sink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
import java | ||
import semmle.code.java.dataflow.DataFlow | ||
import DataFlow | ||
|
||
class ThisFlowConfig extends Configuration { | ||
ThisFlowConfig() { this = "ThisFlowConfig" } | ||
|
||
override predicate isSource(Node src) { | ||
exists(PostUpdateNode cie | cie.asExpr() instanceof ClassInstanceExpr | | ||
module ThisFlowConfig implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node src) { | ||
exists(DataFlow::PostUpdateNode cie | cie.asExpr() instanceof ClassInstanceExpr | | ||
cie.getPreUpdateNode() = src or cie = src | ||
) | ||
} | ||
|
||
override predicate isSink(Node sink) { any() } | ||
predicate isSink(DataFlow::Node sink) { any() } | ||
} | ||
|
||
from Node n, ThisFlowConfig conf | ||
where conf.hasFlow(_, n) | ||
module ThisFlow = DataFlow::Global<ThisFlowConfig>; | ||
|
||
from DataFlow::Node n | ||
where ThisFlow::flowTo(n) | ||
select n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters