Skip to content

Commit e8fc3c8

Browse files
authored
Merge pull request github#5888 from erik-krogh/casting
Approved by asgerf
2 parents 0ebbb33 + a756ffa commit e8fc3c8

16 files changed

+92
-182
lines changed

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ import javascript
66

77
module Base64 {
88
/** A call to a base64 encoder. */
9-
class Encode extends DataFlow::Node {
10-
Encode::Range encode;
11-
12-
Encode() { this = encode }
13-
9+
class Encode extends DataFlow::Node instanceof Encode::Range {
1410
/** Gets the input passed to the encoder. */
15-
DataFlow::Node getInput() { result = encode.getInput() }
11+
DataFlow::Node getInput() { result = super.getInput() }
1612

1713
/** Gets the base64-encoded output of the encoder. */
18-
DataFlow::Node getOutput() { result = encode.getOutput() }
14+
DataFlow::Node getOutput() { result = super.getOutput() }
1915
}
2016

2117
module Encode {
@@ -34,16 +30,12 @@ module Base64 {
3430
}
3531

3632
/** A call to a base64 decoder. */
37-
class Decode extends DataFlow::Node {
38-
Decode::Range encode;
39-
40-
Decode() { this = encode }
41-
33+
class Decode extends DataFlow::Node instanceof Decode::Range {
4234
/** Gets the base64-encoded input passed to the decoder. */
43-
DataFlow::Node getInput() { result = encode.getInput() }
35+
DataFlow::Node getInput() { result = super.getInput() }
4436

4537
/** Gets the output of the decoder. */
46-
DataFlow::Node getOutput() { result = encode.getOutput() }
38+
DataFlow::Node getOutput() { result = super.getOutput() }
4739
}
4840

4941
module Decode {

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ module Closure {
88
/**
99
* A reference to a Closure namespace.
1010
*/
11-
class ClosureNamespaceRef extends DataFlow::Node {
12-
ClosureNamespaceRef::Range range;
13-
14-
ClosureNamespaceRef() { this = range }
15-
11+
class ClosureNamespaceRef extends DataFlow::Node instanceof ClosureNamespaceRef::Range {
1612
/**
1713
* Gets the namespace being referenced.
1814
*/
19-
string getClosureNamespace() { result = range.getClosureNamespace() }
15+
string getClosureNamespace() { result = super.getClosureNamespace() }
2016
}
2117

2218
module ClosureNamespaceRef {
@@ -36,8 +32,7 @@ module Closure {
3632
/**
3733
* A data flow node that returns the value of a closure namespace.
3834
*/
39-
class ClosureNamespaceAccess extends ClosureNamespaceRef {
40-
override ClosureNamespaceAccess::Range range;
35+
class ClosureNamespaceAccess extends ClosureNamespaceRef instanceof ClosureNamespaceAccess::Range {
4136
}
4237

4338
module ClosureNamespaceAccess {
@@ -81,7 +76,7 @@ module Closure {
8176
* A top-level call to `goog.provide`.
8277
*/
8378
class ClosureProvideCall extends ClosureNamespaceRef, DataFlow::MethodCallNode {
84-
override DefaultClosureProvideCall range;
79+
ClosureProvideCall() { this instanceof DefaultClosureProvideCall }
8580
}
8681

8782
/**
@@ -95,7 +90,7 @@ module Closure {
9590
* A call to `goog.require`.
9691
*/
9792
class ClosureRequireCall extends ClosureNamespaceAccess, DataFlow::MethodCallNode {
98-
override DefaultClosureRequireCall range;
93+
ClosureRequireCall() { this instanceof DefaultClosureRequireCall }
9994
}
10095

10196
/**
@@ -112,7 +107,7 @@ module Closure {
112107
* A top-level call to `goog.module` or `goog.declareModuleId`.
113108
*/
114109
class ClosureModuleDeclaration extends ClosureNamespaceRef, DataFlow::MethodCallNode {
115-
override DefaultClosureModuleDeclaration range;
110+
ClosureModuleDeclaration() { this instanceof DefaultClosureModuleDeclaration }
116111
}
117112

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

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,20 @@ private import javascript
1616
* ~A.indexOf(B)
1717
* ```
1818
*/
19-
class InclusionTest extends DataFlow::Node {
20-
InclusionTest::Range range;
21-
22-
InclusionTest() { this = range }
23-
19+
class InclusionTest extends DataFlow::Node instanceof InclusionTest::Range {
2420
/** Gets the `A` in `A.includes(B)`. */
25-
DataFlow::Node getContainerNode() { result = range.getContainerNode() }
21+
DataFlow::Node getContainerNode() { result = super.getContainerNode() }
2622

2723
/** Gets the `B` in `A.includes(B)`. */
28-
DataFlow::Node getContainedNode() { result = range.getContainedNode() }
24+
DataFlow::Node getContainedNode() { result = super.getContainedNode() }
2925

3026
/**
3127
* Gets the polarity of the check.
3228
*
3329
* If the polarity is `false` the check returns `true` if the container does not contain
3430
* the given element.
3531
*/
36-
boolean getPolarity() { result = range.getPolarity() }
32+
boolean getPolarity() { result = super.getPolarity() }
3733
}
3834

3935
module InclusionTest {

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,31 @@ import javascript
99
*
1010
* Additional candidates can be added by subclassing `MembershipCandidate::Range`
1111
*/
12-
class MembershipCandidate extends DataFlow::Node {
13-
MembershipCandidate::Range range;
14-
15-
MembershipCandidate() { this = range }
16-
12+
class MembershipCandidate extends DataFlow::Node instanceof MembershipCandidate::Range {
1713
/**
1814
* Gets the expression that performs the membership test, if any.
1915
*/
20-
DataFlow::Node getTest() { result = range.getTest() }
16+
DataFlow::Node getTest() { result = super.getTest() }
2117

2218
/**
2319
* Gets a string that this candidate is tested against, if
2420
* it can be determined.
2521
*/
26-
string getAMemberString() { result = range.getAMemberString() }
22+
string getAMemberString() { result = super.getAMemberString() }
2723

2824
/**
2925
* Gets a node that this candidate is tested against, if
3026
* it can be determined.
3127
*/
32-
DataFlow::Node getAMemberNode() { result = range.getAMemberNode() }
28+
DataFlow::Node getAMemberNode() { result = super.getAMemberNode() }
3329

3430
/**
3531
* Gets the polarity of the test.
3632
*
3733
* If the polarity is `false` the test returns `true` if the
3834
* collection does not contain this candidate.
3935
*/
40-
boolean getTestPolarity() { result = range.getTestPolarity() }
36+
boolean getTestPolarity() { result = super.getTestPolarity() }
4137
}
4238

4339
/**

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

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,24 @@ module StringOps {
88
/**
99
* A expression that is equivalent to `A.startsWith(B)` or `!A.startsWith(B)`.
1010
*/
11-
class StartsWith extends DataFlow::Node {
12-
StartsWith::Range range;
13-
14-
StartsWith() { range = this }
15-
11+
class StartsWith extends DataFlow::Node instanceof StartsWith::Range {
1612
/**
1713
* Gets the `A` in `A.startsWith(B)`.
1814
*/
19-
DataFlow::Node getBaseString() { result = range.getBaseString() }
15+
DataFlow::Node getBaseString() { result = super.getBaseString() }
2016

2117
/**
2218
* Gets the `B` in `A.startsWith(B)`.
2319
*/
24-
DataFlow::Node getSubstring() { result = range.getSubstring() }
20+
DataFlow::Node getSubstring() { result = super.getSubstring() }
2521

2622
/**
2723
* Gets the polarity of the check.
2824
*
2925
* If the polarity is `false` the check returns `true` if the string does not start
3026
* with the given substring.
3127
*/
32-
boolean getPolarity() { result = range.getPolarity() }
28+
boolean getPolarity() { result = super.getPolarity() }
3329
}
3430

3531
module StartsWith {
@@ -237,28 +233,24 @@ module StringOps {
237233
/**
238234
* An expression that is equivalent to `A.endsWith(B)` or `!A.endsWith(B)`.
239235
*/
240-
class EndsWith extends DataFlow::Node {
241-
EndsWith::Range range;
242-
243-
EndsWith() { this = range }
244-
236+
class EndsWith extends DataFlow::Node instanceof EndsWith::Range {
245237
/**
246238
* Gets the `A` in `A.startsWith(B)`.
247239
*/
248-
DataFlow::Node getBaseString() { result = range.getBaseString() }
240+
DataFlow::Node getBaseString() { result = super.getBaseString() }
249241

250242
/**
251243
* Gets the `B` in `A.startsWith(B)`.
252244
*/
253-
DataFlow::Node getSubstring() { result = range.getSubstring() }
245+
DataFlow::Node getSubstring() { result = super.getSubstring() }
254246

255247
/**
256248
* Gets the polarity if the check.
257249
*
258250
* If the polarity is `false` the check returns `true` if the string does not end
259251
* with the given substring.
260252
*/
261-
boolean getPolarity() { result = range.getPolarity() }
253+
boolean getPolarity() { result = super.getPolarity() }
262254
}
263255

264256
module EndsWith {
@@ -662,39 +654,35 @@ module StringOps {
662654
* if (!match) { ... } // <--- 'match' is the RegExpTest
663655
* ```
664656
*/
665-
class RegExpTest extends DataFlow::Node {
666-
RegExpTest::Range range;
667-
668-
RegExpTest() { this = range }
669-
657+
class RegExpTest extends DataFlow::Node instanceof RegExpTest::Range {
670658
/**
671659
* Gets the AST of the regular expression used in the test, if it can be seen locally.
672660
*/
673661
RegExpTerm getRegExp() {
674662
result = getRegExpOperand().getALocalSource().(DataFlow::RegExpCreationNode).getRoot()
675663
or
676-
result = range.getRegExpOperand(true).asExpr().(StringLiteral).asRegExp()
664+
result = super.getRegExpOperand(true).asExpr().(StringLiteral).asRegExp()
677665
}
678666

679667
/**
680668
* Gets the data flow node corresponding to the regular expression object used in the test.
681669
*
682670
* In some cases this represents a string value being coerced to a RegExp object.
683671
*/
684-
DataFlow::Node getRegExpOperand() { result = range.getRegExpOperand(_) }
672+
DataFlow::Node getRegExpOperand() { result = super.getRegExpOperand(_) }
685673

686674
/**
687675
* Gets the data flow node corresponding to the string being tested against the regular expression.
688676
*/
689-
DataFlow::Node getStringOperand() { result = range.getStringOperand() }
677+
DataFlow::Node getStringOperand() { result = super.getStringOperand() }
690678

691679
/**
692680
* Gets the return value indicating that the string matched the regular expression.
693681
*
694682
* For example, for `regexp.exec(str) == null`, the polarity is `false`, and for
695683
* `regexp.exec(str) != null` the polarity is `true`.
696684
*/
697-
boolean getPolarity() { result = range.getPolarity() }
685+
boolean getPolarity() { result = super.getPolarity() }
698686
}
699687

700688
/**

0 commit comments

Comments
 (0)