Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c17a5c

Browse files
committed
Ruby: replace "instance" label with a call to new
1 parent 5858732 commit 9c17a5c

3 files changed

Lines changed: 4 additions & 16 deletions

File tree

ruby/ql/lib/codeql/ruby/ApiGraphs.qll

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module API {
8888
* This predicate may have multiple results when there are multiple constructor calls invoking this API component.
8989
* Consider using `getAnInstantiation()` if there is a need to distinguish between individual constructor calls.
9090
*/
91-
Node getInstance() { result = this.getASubclass().getASuccessor(Label::instance()) }
91+
Node getInstance() { result = this.getASubclass().getReturn("new") }
9292

9393
/**
9494
* Gets a node representing the result of calling a method on the receiver represented by this node.
@@ -307,15 +307,6 @@ module API {
307307
node.asExpr() = call.getReceiver() and
308308
name = call.getExpr().getMethodName() and
309309
lbl = Label::return(name) and
310-
name != "new" and
311-
ref.asExpr() = call
312-
)
313-
or
314-
// Calling the `new` method on a node that is a use of `base`, which creates a new instance
315-
exists(ExprNodes::MethodCallCfgNode call |
316-
node.asExpr() = call.getReceiver() and
317-
lbl = Label::instance() and
318-
call.getExpr().getMethodName() = "new" and
319310
ref.asExpr() = call
320311
)
321312
}
@@ -439,9 +430,6 @@ private module Label {
439430
/** Gets the `member` edge label for the unknown member. */
440431
string unknownMember() { result = "getUnknownMember()" }
441432

442-
/** Gets the `instance` edge label. */
443-
string instance() { result = "instance" }
444-
445433
/** Gets the `return` edge label. */
446434
bindingset[m]
447435
bindingset[result]

ruby/ql/test/library-tests/dataflow/api-graphs/ApiGraphs.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ classMethodCalls
22
| test1.rb:58:1:58:8 | Use getMember("M1").getMember("C1").getReturn("m") |
33
| test1.rb:59:1:59:8 | Use getMember("M2").getMember("C3").getReturn("m") |
44
instanceMethodCalls
5-
| test1.rb:61:1:61:12 | Use getMember("M1").getMember("C1").instance.getReturn("m") |
6-
| test1.rb:62:1:62:12 | Use getMember("M2").getMember("C3").instance.getReturn("m") |
5+
| test1.rb:61:1:61:12 | Use getMember("M1").getMember("C1").getReturn("new").getReturn("m") |
6+
| test1.rb:62:1:62:12 | Use getMember("M2").getMember("C3").getReturn("new").getReturn("m") |

ruby/ql/test/library-tests/dataflow/api-graphs/test1.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
rescue AttributeError => e #$ use=getMember("AttributeError")
1010
Kernel.print(e) #$ use=getMember("Kernel").getReturn("print")
1111
end
12-
Unknown.new.run #$ use=getMember("Unknown").instance.getReturn("run")
12+
Unknown.new.run #$ use=getMember("Unknown").getReturn("new").getReturn("run")
1313
Foo::Bar::Baz #$ use=getMember("Foo").getMember("Bar").getMember("Baz")
1414

1515
Const = [1, 2, 3] #$ use=getMember("Array").getReturn("[]")

0 commit comments

Comments
 (0)