Skip to content

Commit 8d4af3a

Browse files
committed
convert field based range pattern to casting based range pattern
1 parent ec0066d commit 8d4af3a

16 files changed

+108
-136
lines changed

javascript/ql/lib/semmle/javascript/Base64.qll

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ import javascript
77
module Base64 {
88
/** A call to a base64 encoder. */
99
class Encode extends DataFlow::Node {
10-
Encode::Range encode;
11-
12-
Encode() { this = encode }
10+
Encode() { this instanceof Encode::Range }
1311

1412
/** Gets the input passed to the encoder. */
15-
DataFlow::Node getInput() { result = encode.getInput() }
13+
DataFlow::Node getInput() { result = this.(Encode::Range).getInput() }
1614

1715
/** Gets the base64-encoded output of the encoder. */
18-
DataFlow::Node getOutput() { result = encode.getOutput() }
16+
DataFlow::Node getOutput() { result = this.(Encode::Range).getOutput() }
1917
}
2018

2119
module Encode {
@@ -35,15 +33,13 @@ module Base64 {
3533

3634
/** A call to a base64 decoder. */
3735
class Decode extends DataFlow::Node {
38-
Decode::Range encode;
39-
40-
Decode() { this = encode }
36+
Decode() { this instanceof Decode::Range }
4137

4238
/** Gets the base64-encoded input passed to the decoder. */
43-
DataFlow::Node getInput() { result = encode.getInput() }
39+
DataFlow::Node getInput() { result = this.(Decode::Range).getInput() }
4440

4541
/** Gets the output of the decoder. */
46-
DataFlow::Node getOutput() { result = encode.getOutput() }
42+
DataFlow::Node getOutput() { result = this.(Decode::Range).getOutput() }
4743
}
4844

4945
module Decode {

javascript/ql/lib/semmle/javascript/Closure.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ module Closure {
99
* A reference to a Closure namespace.
1010
*/
1111
class ClosureNamespaceRef extends DataFlow::Node {
12-
ClosureNamespaceRef::Range range;
13-
14-
ClosureNamespaceRef() { this = range }
12+
ClosureNamespaceRef() { this instanceof ClosureNamespaceRef::Range }
1513

1614
/**
1715
* Gets the namespace being referenced.
1816
*/
19-
string getClosureNamespace() { result = range.getClosureNamespace() }
17+
string getClosureNamespace() {
18+
result = this.(ClosureNamespaceRef::Range).getClosureNamespace()
19+
}
2020
}
2121

2222
module ClosureNamespaceRef {
@@ -37,7 +37,7 @@ module Closure {
3737
* A data flow node that returns the value of a closure namespace.
3838
*/
3939
class ClosureNamespaceAccess extends ClosureNamespaceRef {
40-
override ClosureNamespaceAccess::Range range;
40+
ClosureNamespaceAccess() { this instanceof ClosureNamespaceAccess::Range }
4141
}
4242

4343
module ClosureNamespaceAccess {
@@ -81,7 +81,7 @@ module Closure {
8181
* A top-level call to `goog.provide`.
8282
*/
8383
class ClosureProvideCall extends ClosureNamespaceRef, DataFlow::MethodCallNode {
84-
override DefaultClosureProvideCall range;
84+
ClosureProvideCall() { this instanceof DefaultClosureProvideCall }
8585
}
8686

8787
/**
@@ -95,7 +95,7 @@ module Closure {
9595
* A call to `goog.require`.
9696
*/
9797
class ClosureRequireCall extends ClosureNamespaceAccess, DataFlow::MethodCallNode {
98-
override DefaultClosureRequireCall range;
98+
ClosureRequireCall() { this instanceof DefaultClosureRequireCall }
9999
}
100100

101101
/**
@@ -112,7 +112,7 @@ module Closure {
112112
* A top-level call to `goog.module` or `goog.declareModuleId`.
113113
*/
114114
class ClosureModuleDeclaration extends ClosureNamespaceRef, DataFlow::MethodCallNode {
115-
override DefaultClosureModuleDeclaration range;
115+
ClosureModuleDeclaration() { this instanceof DefaultClosureModuleDeclaration }
116116
}
117117

118118
private GlobalVariable googVariable() { variables(result, "goog", any(GlobalScope sc)) }

javascript/ql/lib/semmle/javascript/InclusionTests.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,21 @@ private import javascript
1717
* ```
1818
*/
1919
class InclusionTest extends DataFlow::Node {
20-
InclusionTest::Range range;
21-
22-
InclusionTest() { this = range }
20+
InclusionTest() { this instanceof InclusionTest::Range }
2321

2422
/** Gets the `A` in `A.includes(B)`. */
25-
DataFlow::Node getContainerNode() { result = range.getContainerNode() }
23+
DataFlow::Node getContainerNode() { result = this.(InclusionTest::Range).getContainerNode() }
2624

2725
/** Gets the `B` in `A.includes(B)`. */
28-
DataFlow::Node getContainedNode() { result = range.getContainedNode() }
26+
DataFlow::Node getContainedNode() { result = this.(InclusionTest::Range).getContainedNode() }
2927

3028
/**
3129
* Gets the polarity of the check.
3230
*
3331
* If the polarity is `false` the check returns `true` if the container does not contain
3432
* the given element.
3533
*/
36-
boolean getPolarity() { result = range.getPolarity() }
34+
boolean getPolarity() { result = this.(InclusionTest::Range).getPolarity() }
3735
}
3836

3937
module InclusionTest {

javascript/ql/lib/semmle/javascript/MembershipCandidates.qll

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,32 @@ import javascript
1010
* Additional candidates can be added by subclassing `MembershipCandidate::Range`
1111
*/
1212
class MembershipCandidate extends DataFlow::Node {
13-
MembershipCandidate::Range range;
14-
15-
MembershipCandidate() { this = range }
13+
MembershipCandidate() { this instanceof MembershipCandidate::Range }
1614

1715
/**
1816
* Gets the expression that performs the membership test, if any.
1917
*/
20-
DataFlow::Node getTest() { result = range.getTest() }
18+
DataFlow::Node getTest() { result = this.(MembershipCandidate::Range).getTest() }
2119

2220
/**
2321
* Gets a string that this candidate is tested against, if
2422
* it can be determined.
2523
*/
26-
string getAMemberString() { result = range.getAMemberString() }
24+
string getAMemberString() { result = this.(MembershipCandidate::Range).getAMemberString() }
2725

2826
/**
2927
* Gets a node that this candidate is tested against, if
3028
* it can be determined.
3129
*/
32-
DataFlow::Node getAMemberNode() { result = range.getAMemberNode() }
30+
DataFlow::Node getAMemberNode() { result = this.(MembershipCandidate::Range).getAMemberNode() }
3331

3432
/**
3533
* Gets the polarity of the test.
3634
*
3735
* If the polarity is `false` the test returns `true` if the
3836
* collection does not contain this candidate.
3937
*/
40-
boolean getTestPolarity() { result = range.getTestPolarity() }
38+
boolean getTestPolarity() { result = this.(MembershipCandidate::Range).getTestPolarity() }
4139
}
4240

4341
/**

javascript/ql/lib/semmle/javascript/StringOps.qll

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,25 @@ module StringOps {
99
* A expression that is equivalent to `A.startsWith(B)` or `!A.startsWith(B)`.
1010
*/
1111
class StartsWith extends DataFlow::Node {
12-
StartsWith::Range range;
13-
14-
StartsWith() { range = this }
12+
StartsWith() { this instanceof StartsWith::Range }
1513

1614
/**
1715
* Gets the `A` in `A.startsWith(B)`.
1816
*/
19-
DataFlow::Node getBaseString() { result = range.getBaseString() }
17+
DataFlow::Node getBaseString() { result = this.(StartsWith::Range).getBaseString() }
2018

2119
/**
2220
* Gets the `B` in `A.startsWith(B)`.
2321
*/
24-
DataFlow::Node getSubstring() { result = range.getSubstring() }
22+
DataFlow::Node getSubstring() { result = this.(StartsWith::Range).getSubstring() }
2523

2624
/**
2725
* Gets the polarity of the check.
2826
*
2927
* If the polarity is `false` the check returns `true` if the string does not start
3028
* with the given substring.
3129
*/
32-
boolean getPolarity() { result = range.getPolarity() }
30+
boolean getPolarity() { result = this.(StartsWith::Range).getPolarity() }
3331
}
3432

3533
module StartsWith {
@@ -238,27 +236,25 @@ module StringOps {
238236
* An expression that is equivalent to `A.endsWith(B)` or `!A.endsWith(B)`.
239237
*/
240238
class EndsWith extends DataFlow::Node {
241-
EndsWith::Range range;
242-
243-
EndsWith() { this = range }
239+
EndsWith() { this instanceof EndsWith::Range }
244240

245241
/**
246242
* Gets the `A` in `A.startsWith(B)`.
247243
*/
248-
DataFlow::Node getBaseString() { result = range.getBaseString() }
244+
DataFlow::Node getBaseString() { result = this.(EndsWith::Range).getBaseString() }
249245

250246
/**
251247
* Gets the `B` in `A.startsWith(B)`.
252248
*/
253-
DataFlow::Node getSubstring() { result = range.getSubstring() }
249+
DataFlow::Node getSubstring() { result = this.(EndsWith::Range).getSubstring() }
254250

255251
/**
256252
* Gets the polarity if the check.
257253
*
258254
* If the polarity is `false` the check returns `true` if the string does not end
259255
* with the given substring.
260256
*/
261-
boolean getPolarity() { result = range.getPolarity() }
257+
boolean getPolarity() { result = this.(EndsWith::Range).getPolarity() }
262258
}
263259

264260
module EndsWith {
@@ -663,38 +659,36 @@ module StringOps {
663659
* ```
664660
*/
665661
class RegExpTest extends DataFlow::Node {
666-
RegExpTest::Range range;
667-
668-
RegExpTest() { this = range }
662+
RegExpTest() { this instanceof RegExpTest::Range }
669663

670664
/**
671665
* Gets the AST of the regular expression used in the test, if it can be seen locally.
672666
*/
673667
RegExpTerm getRegExp() {
674668
result = getRegExpOperand().getALocalSource().(DataFlow::RegExpCreationNode).getRoot()
675669
or
676-
result = range.getRegExpOperand(true).asExpr().(StringLiteral).asRegExp()
670+
result = this.(RegExpTest::Range).getRegExpOperand(true).asExpr().(StringLiteral).asRegExp()
677671
}
678672

679673
/**
680674
* Gets the data flow node corresponding to the regular expression object used in the test.
681675
*
682676
* In some cases this represents a string value being coerced to a RegExp object.
683677
*/
684-
DataFlow::Node getRegExpOperand() { result = range.getRegExpOperand(_) }
678+
DataFlow::Node getRegExpOperand() { result = this.(RegExpTest::Range).getRegExpOperand(_) }
685679

686680
/**
687681
* Gets the data flow node corresponding to the string being tested against the regular expression.
688682
*/
689-
DataFlow::Node getStringOperand() { result = range.getStringOperand() }
683+
DataFlow::Node getStringOperand() { result = this.(RegExpTest::Range).getStringOperand() }
690684

691685
/**
692686
* Gets the return value indicating that the string matched the regular expression.
693687
*
694688
* For example, for `regexp.exec(str) == null`, the polarity is `false`, and for
695689
* `regexp.exec(str) != null` the polarity is `true`.
696690
*/
697-
boolean getPolarity() { result = range.getPolarity() }
691+
boolean getPolarity() { result = this.(RegExpTest::Range).getPolarity() }
698692
}
699693

700694
/**

0 commit comments

Comments
 (0)