Skip to content

Commit 8ce7fdc

Browse files
authored
Merge pull request #284 from github/hvitved/instanceof-test
Use `instanceof` base classes
2 parents 51d729a + 3594794 commit 8ce7fdc

File tree

8 files changed

+42
-75
lines changed

8 files changed

+42
-75
lines changed

.devcontainer/post_attach.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -xe
33

44
echo "Check installed CodeQL version"
55
CURRENT_CODEQL_BIN=$(readlink -e /usr/local/bin/codeql || echo "")
6-
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
6+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1)
77

88
BASE_DIR=/home/vscode/codeql-binaries
99
mkdir -p "${BASE_DIR}"

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
- uses: actions/checkout@v2
7676
- name: Fetch CodeQL
7777
run: |
78-
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
78+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1)
7979
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST"
8080
unzip -q codeql-linux64.zip
8181
env:
@@ -185,7 +185,7 @@ jobs:
185185
- name: Fetch CodeQL
186186
shell: bash
187187
run: |
188-
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
188+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1)
189189
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql.zip "$LATEST"
190190
unzip -q codeql.zip
191191
env:

.github/workflows/dataset_measure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- name: Fetch CodeQL
2727
run: |
28-
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
28+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1)
2929
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST"
3030
unzip -q codeql-linux64.zip
3131
env:

.github/workflows/qhelp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
2424
- name: Fetch CodeQL
2525
run: |
26-
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
26+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1)
2727
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST"
2828
unzip -q codeql-linux64.zip
2929
env:

ql/lib/codeql/ruby/Concepts.qll

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ private import codeql.ruby.dataflow.RemoteFlowSources
1616
* Extend this class to refine existing API models. If you want to model new APIs,
1717
* extend `SqlExecution::Range` instead.
1818
*/
19-
class SqlExecution extends DataFlow::Node {
20-
SqlExecution::Range range;
21-
22-
SqlExecution() { this = range }
23-
19+
class SqlExecution extends DataFlow::Node instanceof SqlExecution::Range {
2420
/** Gets the argument that specifies the SQL statements to be executed. */
25-
DataFlow::Node getSql() { result = range.getSql() }
21+
DataFlow::Node getSql() { result = super.getSql() }
2622
}
2723

2824
/** Provides a class for modeling new SQL execution APIs. */
@@ -46,26 +42,23 @@ module SqlExecution {
4642
* Extend this class to refine existing API models. If you want to model new APIs,
4743
* extend `Escaping::Range` instead.
4844
*/
49-
class Escaping extends DataFlow::Node {
50-
Escaping::Range range;
51-
45+
class Escaping extends DataFlow::Node instanceof Escaping::Range {
5246
Escaping() {
53-
this = range and
5447
// escapes that don't have _both_ input/output defined are not valid
55-
exists(range.getAnInput()) and
56-
exists(range.getOutput())
48+
exists(super.getAnInput()) and
49+
exists(super.getOutput())
5750
}
5851

5952
/** Gets an input that will be escaped. */
60-
DataFlow::Node getAnInput() { result = range.getAnInput() }
53+
DataFlow::Node getAnInput() { result = super.getAnInput() }
6154

6255
/** Gets the output that contains the escaped data. */
63-
DataFlow::Node getOutput() { result = range.getOutput() }
56+
DataFlow::Node getOutput() { result = super.getOutput() }
6457

6558
/**
6659
* Gets the context that this function escapes for, such as `html`, or `url`.
6760
*/
68-
string getKind() { result = range.getKind() }
61+
string getKind() { result = super.getKind() }
6962
}
7063

7164
/** Provides a class for modeling new escaping APIs. */
@@ -103,7 +96,7 @@ module Escaping {
10396
* `<p>{}</p>`.
10497
*/
10598
class HtmlEscaping extends Escaping {
106-
HtmlEscaping() { range.getKind() = Escaping::getHtmlKind() }
99+
HtmlEscaping() { super.getKind() = Escaping::getHtmlKind() }
107100
}
108101

109102
/** Provides classes for modeling HTTP-related APIs. */
@@ -116,29 +109,25 @@ module HTTP {
116109
* Extend this class to refine existing API models. If you want to model new APIs,
117110
* extend `RouteSetup::Range` instead.
118111
*/
119-
class RouteSetup extends DataFlow::Node {
120-
RouteSetup::Range range;
121-
122-
RouteSetup() { this = range }
123-
112+
class RouteSetup extends DataFlow::Node instanceof RouteSetup::Range {
124113
/** Gets the URL pattern for this route, if it can be statically determined. */
125-
string getUrlPattern() { result = range.getUrlPattern() }
114+
string getUrlPattern() { result = super.getUrlPattern() }
126115

127116
/**
128117
* Gets a function that will handle incoming requests for this route, if any.
129118
*
130119
* NOTE: This will be modified in the near future to have a `RequestHandler` result, instead of a `Method`.
131120
*/
132-
Method getARequestHandler() { result = range.getARequestHandler() }
121+
Method getARequestHandler() { result = super.getARequestHandler() }
133122

134123
/**
135124
* Gets a parameter that will receive parts of the url when handling incoming
136125
* requests for this route, if any. These automatically become a `RemoteFlowSource`.
137126
*/
138-
Parameter getARoutedParameter() { result = range.getARoutedParameter() }
127+
Parameter getARoutedParameter() { result = super.getARoutedParameter() }
139128

140129
/** Gets a string that identifies the framework used for this route setup. */
141-
string getFramework() { result = range.getFramework() }
130+
string getFramework() { result = super.getFramework() }
142131
}
143132

144133
/** Provides a class for modeling new HTTP routing APIs. */
@@ -185,19 +174,15 @@ module HTTP {
185174
* Extend this class to refine existing API models. If you want to model new APIs,
186175
* extend `RequestHandler::Range` instead.
187176
*/
188-
class RequestHandler extends Method {
189-
RequestHandler::Range range;
190-
191-
RequestHandler() { this = range }
192-
177+
class RequestHandler extends Method instanceof RequestHandler::Range {
193178
/**
194179
* Gets a parameter that could receive parts of the url when handling incoming
195180
* requests, if any. These automatically become a `RemoteFlowSource`.
196181
*/
197-
Parameter getARoutedParameter() { result = range.getARoutedParameter() }
182+
Parameter getARoutedParameter() { result = super.getARoutedParameter() }
198183

199184
/** Gets a string that identifies the framework used for this route setup. */
200-
string getFramework() { result = range.getFramework() }
185+
string getFramework() { result = super.getFramework() }
201186
}
202187

203188
/** Provides a class for modeling new HTTP request handlers. */
@@ -253,16 +238,12 @@ module HTTP {
253238
* Extend this class to refine existing API models. If you want to model new APIs,
254239
* extend `HttpResponse::Range` instead.
255240
*/
256-
class HttpResponse extends DataFlow::Node {
257-
HttpResponse::Range range;
258-
259-
HttpResponse() { this = range }
260-
241+
class HttpResponse extends DataFlow::Node instanceof HttpResponse::Range {
261242
/** Gets the data-flow node that specifies the body of this HTTP response. */
262-
DataFlow::Node getBody() { result = range.getBody() }
243+
DataFlow::Node getBody() { result = super.getBody() }
263244

264245
/** Gets the mimetype of this HTTP response, if it can be statically determined. */
265-
string getMimetype() { result = range.getMimetype() }
246+
string getMimetype() { result = super.getMimetype() }
266247
}
267248

268249
/** Provides a class for modeling new HTTP response APIs. */
@@ -308,13 +289,9 @@ module HTTP {
308289
* Extend this class to refine existing API models. If you want to model new APIs,
309290
* extend `HttpRedirectResponse::Range` instead.
310291
*/
311-
class HttpRedirectResponse extends HttpResponse {
312-
override HttpRedirectResponse::Range range;
313-
314-
HttpRedirectResponse() { this = range }
315-
292+
class HttpRedirectResponse extends HttpResponse instanceof HttpRedirectResponse::Range {
316293
/** Gets the data-flow node that specifies the location of this HTTP redirect response. */
317-
DataFlow::Node getRedirectLocation() { result = range.getRedirectLocation() }
294+
DataFlow::Node getRedirectLocation() { result = super.getRedirectLocation() }
318295
}
319296

320297
/** Provides a class for modeling new HTTP redirect response APIs. */

ql/lib/codeql/ruby/ast/Variable.qll

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,20 @@ class LocalVariable extends Variable, TLocalVariable {
5252
}
5353

5454
/** A global variable. */
55-
class GlobalVariable extends VariableReal, TGlobalVariable {
56-
override GlobalVariable::Range range;
57-
55+
class GlobalVariable extends VariableReal, TGlobalVariable instanceof GlobalVariable::Range {
5856
final override GlobalVariableAccess getAnAccess() { result.getVariable() = this }
5957
}
6058

6159
/** An instance variable. */
62-
class InstanceVariable extends VariableReal, TInstanceVariable {
63-
override InstanceVariable::Range range;
64-
60+
class InstanceVariable extends VariableReal, TInstanceVariable instanceof InstanceVariable::Range {
6561
/** Holds is this variable is a class instance variable. */
66-
final predicate isClassInstanceVariable() { range.isClassInstanceVariable() }
62+
final predicate isClassInstanceVariable() { super.isClassInstanceVariable() }
6763

6864
final override InstanceVariableAccess getAnAccess() { result.getVariable() = this }
6965
}
7066

7167
/** A class variable. */
72-
class ClassVariable extends VariableReal, TClassVariable {
73-
override ClassVariable::Range range;
74-
68+
class ClassVariable extends VariableReal, TClassVariable instanceof ClassVariable::Range {
7569
final override ClassVariableAccess getAnAccess() { result.getVariable() = this }
7670
}
7771

ql/lib/codeql/ruby/ast/internal/Variable.qll

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -400,24 +400,22 @@ module LocalVariable {
400400
}
401401
}
402402

403-
class VariableReal extends Variable, TVariableReal {
404-
VariableReal::Range range;
403+
class VariableReal extends Variable, TVariableReal instanceof VariableReal::Range {
404+
final override string getName() { result = VariableReal::Range.super.getName() }
405405

406-
VariableReal() { range = this }
406+
final override Location getLocation() { result = VariableReal::Range.super.getLocation() }
407407

408-
final override string getName() { result = range.getName() }
409-
410-
final override Location getLocation() { result = range.getLocation() }
411-
412-
final override Scope getDeclaringScope() { toGenerated(result) = range.getDeclaringScope() }
408+
final override Scope getDeclaringScope() {
409+
toGenerated(result) = VariableReal::Range.super.getDeclaringScope()
410+
}
413411
}
414412

415-
class LocalVariableReal extends VariableReal, LocalVariable, TLocalVariableReal {
416-
override LocalVariable::Range range;
417-
413+
class LocalVariableReal extends VariableReal, LocalVariable, TLocalVariableReal instanceof LocalVariable::Range {
418414
final override LocalVariableAccessReal getAnAccess() { result.getVariable() = this }
419415

420-
final override VariableAccess getDefiningAccess() { result = range.getDefiningAccess() }
416+
final override VariableAccess getDefiningAccess() {
417+
result = LocalVariable::Range.super.getDefiningAccess()
418+
}
421419
}
422420

423421
class LocalVariableSynth extends LocalVariable, TLocalVariableSynth {

ql/lib/codeql/ruby/controlflow/ControlFlowGraph.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ private import internal.Splitting
99
private import internal.Completion
1010

1111
/** An AST node with an associated control-flow graph. */
12-
class CfgScope extends Scope {
13-
CfgScope() { this instanceof CfgScope::Range_ }
14-
12+
class CfgScope extends Scope instanceof CfgScope::Range_ {
1513
/** Gets the CFG scope that this scope is nested under, if any. */
1614
final CfgScope getOuterCfgScope() {
1715
exists(AstNode parent |

0 commit comments

Comments
 (0)