Skip to content

Commit 3548544

Browse files
committed
JS: Avoid some uses of deprecated guard classes in tests
1 parent a568d8c commit 3548544

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

javascript/ql/test/library-tests/LabelledBarrierGuards/LabelledBarrierGuards.ql

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,15 @@ module TestConfig implements DataFlow::StateConfigSig {
2020
)
2121
}
2222

23-
additional predicate isBarrierGuard(DataFlow::BarrierGuardNode node) {
24-
node instanceof IsTypeAGuard or
25-
node instanceof IsSanitizedGuard
26-
}
27-
2823
predicate isBarrier(DataFlow::Node node, DataFlow::FlowLabel lbl) {
29-
node = DataFlow::MakeLegacyBarrierGuardLabeled<isBarrierGuard/1>::getABarrierNode(lbl)
24+
node = DataFlow::MakeLabeledBarrierGuard<IsTypeAGuard>::getABarrierNode(lbl) or
25+
node = DataFlow::MakeLabeledBarrierGuard<IsSanitizedGuard>::getABarrierNode(lbl)
3026
}
3127
}
3228

3329
module TestFlow = TaintTracking::GlobalWithState<TestConfig>;
3430

35-
class LegacyConfig extends TaintTracking::Configuration {
31+
deprecated class LegacyConfig extends TaintTracking::Configuration {
3632
LegacyConfig() { this = "LegacyConfig" }
3733

3834
override predicate isSource(DataFlow::Node node, DataFlow::FlowLabel lbl) {
@@ -44,21 +40,18 @@ class LegacyConfig extends TaintTracking::Configuration {
4440
}
4541

4642
override predicate isSanitizerGuard(TaintTracking::SanitizerGuardNode node) {
47-
TestConfig::isBarrierGuard(node)
43+
node instanceof IsTypeAGuardLegacy or
44+
node instanceof IsSanitizedGuardLegacy
4845
}
4946
}
5047

5148
/**
5249
* A condition that checks what kind of value the input is. Not enough to
5350
* sanitize the value, but later sanitizers only need to handle the relevant case.
5451
*/
55-
class IsTypeAGuard extends TaintTracking::LabeledSanitizerGuardNode, DataFlow::CallNode {
52+
class IsTypeAGuard extends DataFlow::CallNode {
5653
IsTypeAGuard() { this.getCalleeName() = "isTypeA" }
5754

58-
override predicate sanitizes(boolean outcome, Expr e, DataFlow::FlowLabel lbl) {
59-
this.blocksExpr(outcome, e, lbl)
60-
}
61-
6255
predicate blocksExpr(boolean outcome, Expr e, DataFlow::FlowLabel lbl) {
6356
e = this.getArgument(0).asExpr() and
6457
(
@@ -69,12 +62,14 @@ class IsTypeAGuard extends TaintTracking::LabeledSanitizerGuardNode, DataFlow::C
6962
}
7063
}
7164

72-
class IsSanitizedGuard extends TaintTracking::LabeledSanitizerGuardNode, DataFlow::CallNode {
73-
IsSanitizedGuard() { this.getCalleeName() = "sanitizeA" or this.getCalleeName() = "sanitizeB" }
74-
65+
deprecated class IsTypeAGuardLegacy extends IsTypeAGuard, TaintTracking::LabeledSanitizerGuardNode {
7566
override predicate sanitizes(boolean outcome, Expr e, DataFlow::FlowLabel lbl) {
7667
this.blocksExpr(outcome, e, lbl)
7768
}
69+
}
70+
71+
class IsSanitizedGuard extends DataFlow::CallNode {
72+
IsSanitizedGuard() { this.getCalleeName() = "sanitizeA" or this.getCalleeName() = "sanitizeB" }
7873

7974
predicate blocksExpr(boolean outcome, Expr e, DataFlow::FlowLabel lbl) {
8075
e = this.getArgument(0).asExpr() and
@@ -87,7 +82,15 @@ class IsSanitizedGuard extends TaintTracking::LabeledSanitizerGuardNode, DataFlo
8782
}
8883
}
8984

90-
import testUtilities.LegacyDataFlowDiff::DataFlowDiff<TestFlow, LegacyConfig>
85+
deprecated class IsSanitizedGuardLegacy extends IsSanitizedGuard,
86+
TaintTracking::LabeledSanitizerGuardNode
87+
{
88+
override predicate sanitizes(boolean outcome, Expr e, DataFlow::FlowLabel lbl) {
89+
this.blocksExpr(outcome, e, lbl)
90+
}
91+
}
92+
93+
deprecated import testUtilities.LegacyDataFlowDiff::DataFlowDiff<TestFlow, LegacyConfig>
9194

9295
from DataFlow::Node source, DataFlow::Node sink
9396
where TestFlow::flow(source, sink)

javascript/ql/test/library-tests/TaintTracking/DataFlowTracking.ql

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,37 @@ module TestConfig implements DataFlow::ConfigSig {
77

88
predicate isSink(DataFlow::Node node) { node = getACall("sink").getAnArgument() }
99

10-
additional predicate isBarrierGuard(DataFlow::BarrierGuardNode node) {
11-
node instanceof BasicBarrierGuard
12-
}
13-
1410
predicate isBarrier(DataFlow::Node node) {
15-
node = DataFlow::MakeLegacyBarrierGuard<isBarrierGuard/1>::getABarrierNode()
11+
node = DataFlow::MakeBarrierGuard<BasicBarrierGuard>::getABarrierNode()
1612
}
1713
}
1814

1915
module TestFlow = DataFlow::Global<TestConfig>;
2016

21-
class BasicBarrierGuard extends DataFlow::BarrierGuardNode, DataFlow::CallNode {
17+
class BasicBarrierGuard extends DataFlow::CallNode {
2218
BasicBarrierGuard() { this = getACall("isSafe") }
2319

24-
override predicate blocks(boolean outcome, Expr e) { this.blocksExpr(outcome, e) }
25-
2620
predicate blocksExpr(boolean outcome, Expr e) {
2721
outcome = true and e = this.getArgument(0).asExpr()
2822
}
2923
}
3024

31-
class LegacyConfig extends DataFlow::Configuration {
25+
deprecated class BasicBarrierGuardLegacy extends DataFlow::BarrierGuardNode, BasicBarrierGuard {
26+
override predicate blocks(boolean outcome, Expr e) { this.blocksExpr(outcome, e) }
27+
}
28+
29+
deprecated class LegacyConfig extends DataFlow::Configuration {
3230
LegacyConfig() { this = "LegacyConfig" }
3331

3432
override predicate isSource(DataFlow::Node source) { TestConfig::isSource(source) }
3533

3634
override predicate isSink(DataFlow::Node sink) { TestConfig::isSink(sink) }
3735

3836
override predicate isBarrierGuard(DataFlow::BarrierGuardNode node) {
39-
TestConfig::isBarrierGuard(node)
37+
node instanceof BasicBarrierGuardLegacy
4038
}
4139
}
4240

43-
import testUtilities.LegacyDataFlowDiff::DataFlowDiff<TestFlow, LegacyConfig>
41+
deprecated import testUtilities.LegacyDataFlowDiff::DataFlowDiff<TestFlow, LegacyConfig>
4442

4543
query predicate flow = TestFlow::flow/2;

0 commit comments

Comments
 (0)