JS: Port SimpleBarrierGuard test

This commit is contained in:
Asger F
2023-10-05 14:48:52 +02:00
parent ff086377cb
commit 9a15a557b4
2 changed files with 30 additions and 14 deletions

View File

@@ -1,3 +1,5 @@
| tst.js:4:10:4:10 | x | tst.js:2:13:2:20 | SOURCE() |
| tst.js:9:14:9:14 | x | tst.js:2:13:2:20 | SOURCE() |
| tst.js:12:10:12:10 | x | tst.js:2:13:2:20 | SOURCE() |
legacyDataFlowDifference
flow
| tst.js:2:13:2:20 | SOURCE() | tst.js:4:10:4:10 | x |
| tst.js:2:13:2:20 | SOURCE() | tst.js:9:14:9:14 | x |
| tst.js:2:13:2:20 | SOURCE() | tst.js:12:10:12:10 | x |

View File

@@ -1,33 +1,47 @@
import javascript
class Configuration extends DataFlow::Configuration {
Configuration() { this = "SimpleBarrierGuard" }
override predicate isSource(DataFlow::Node source) {
module TestConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source.(DataFlow::InvokeNode).getCalleeName() = "SOURCE"
}
override predicate isSink(DataFlow::Node sink) {
predicate isSink(DataFlow::Node sink) {
exists(DataFlow::InvokeNode call |
call.getCalleeName() = "SINK" and
sink = call.getArgument(0)
)
}
override predicate isBarrierGuard(DataFlow::BarrierGuardNode guard) {
guard instanceof SimpleBarrierGuardNode
predicate isBarrier(DataFlow::Node node) {
node = DataFlow::MakeBarrierGuard<SimpleBarrierGuardNode>::getABarrierNode()
}
}
module TestFlow = DataFlow::Global<TestConfig>;
class SimpleBarrierGuardNode extends DataFlow::BarrierGuardNode, DataFlow::InvokeNode {
SimpleBarrierGuardNode() { this.getCalleeName() = "BARRIER" }
override predicate blocks(boolean outcome, Expr e) {
override predicate blocks(boolean outcome, Expr e) { this.blocksExpr(outcome, e) }
predicate blocksExpr(boolean outcome, Expr e) {
outcome = true and
e = this.getArgument(0).asExpr()
}
}
from Configuration cfg, DataFlow::Node source, DataFlow::Node sink
where cfg.hasFlow(source, sink)
select sink, source
class LegacyConfig extends DataFlow::Configuration {
LegacyConfig() { this = "LegacyConfig" }
override predicate isSource(DataFlow::Node source) { TestConfig::isSource(source) }
override predicate isSink(DataFlow::Node sink) { TestConfig::isSink(sink) }
override predicate isBarrierGuard(DataFlow::BarrierGuardNode guard) {
guard instanceof SimpleBarrierGuardNode
}
}
import testUtilities.LegacyDataFlowDiff::DataFlowDiff<TestFlow, LegacyConfig>
query predicate flow = TestFlow::flow/2;