Skip to content

Commit 8646bff

Browse files
committed
Ruby: Remove ReturnValue as access path for constructors
1 parent c5dc883 commit 8646bff

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

ruby/ql/src/utils/modeleditor/FrameworkModeAccessPaths.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ private import ruby
1010
private import codeql.ruby.AST
1111
private import codeql.ruby.ApiGraphs
1212
private import queries.modeling.internal.Util as Util
13+
private import ModelEditor
1314

1415
predicate simpleParameters(string type, string path, string value, DataFlow::Node node) {
1516
exists(DataFlow::MethodNode methodNode, DataFlow::ParameterNode paramNode |
@@ -58,7 +59,8 @@ predicate blockArguments(string type, string path, string value, DataFlow::Node
5859
predicate returnValue(string type, string path, string value, DataFlow::Node node) {
5960
exists(DataFlow::MethodNode methodNode, DataFlow::Node returnNode |
6061
methodNode.getLocation().getFile() instanceof Util::RelevantFile and
61-
returnNode = methodNode.getAReturnNode()
62+
returnNode = methodNode.getAReturnNode() and
63+
not isConstructor(methodNode) // A constructor doesn't have a return value
6264
|
6365
Util::pathToMethod(methodNode, type, path) and
6466
value = "ReturnValue" and

ruby/ql/src/utils/modeleditor/ModelEditor.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ string getNamespace(File file) {
3232
)
3333
}
3434

35+
/**
36+
* Holds if this method is a constructor for a module.
37+
*/
38+
predicate isConstructor(DataFlow::MethodNode method) {
39+
method.getMethodName() = "initialize" and
40+
exists(DataFlow::ModuleNode m | m.getOwnInstanceMethod(method.getMethodName()) = method)
41+
}
42+
3543
abstract class Endpoint instanceof DataFlow::Node {
3644
string getNamespace() { result = getNamespace(super.getLocation().getFile()) }
3745

@@ -153,10 +161,7 @@ class MethodEndpoint extends Endpoint instanceof DataFlow::MethodNode {
153161
/**
154162
* Holds if this method is a constructor for a module.
155163
*/
156-
private predicate isConstructor() {
157-
super.getMethodName() = "initialize" and
158-
exists(DataFlow::ModuleNode m | m.getOwnInstanceMethod(super.getMethodName()) = this)
159-
}
164+
private predicate isConstructor() { isConstructor(this) }
160165
}
161166

162167
string methodClassification(Call method) {

0 commit comments

Comments
 (0)