mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
Ruby: replace "instance" label with a call to new
This commit is contained in:
@@ -88,7 +88,7 @@ module API {
|
||||
* This predicate may have multiple results when there are multiple constructor calls invoking this API component.
|
||||
* Consider using `getAnInstantiation()` if there is a need to distinguish between individual constructor calls.
|
||||
*/
|
||||
Node getInstance() { result = this.getASubclass().getASuccessor(Label::instance()) }
|
||||
Node getInstance() { result = this.getASubclass().getReturn("new") }
|
||||
|
||||
/**
|
||||
* Gets a node representing the result of calling a method on the receiver represented by this node.
|
||||
@@ -307,15 +307,6 @@ module API {
|
||||
node.asExpr() = call.getReceiver() and
|
||||
name = call.getExpr().getMethodName() and
|
||||
lbl = Label::return(name) and
|
||||
name != "new" and
|
||||
ref.asExpr() = call
|
||||
)
|
||||
or
|
||||
// Calling the `new` method on a node that is a use of `base`, which creates a new instance
|
||||
exists(ExprNodes::MethodCallCfgNode call |
|
||||
node.asExpr() = call.getReceiver() and
|
||||
lbl = Label::instance() and
|
||||
call.getExpr().getMethodName() = "new" and
|
||||
ref.asExpr() = call
|
||||
)
|
||||
}
|
||||
@@ -439,9 +430,6 @@ private module Label {
|
||||
/** Gets the `member` edge label for the unknown member. */
|
||||
string unknownMember() { result = "getUnknownMember()" }
|
||||
|
||||
/** Gets the `instance` edge label. */
|
||||
string instance() { result = "instance" }
|
||||
|
||||
/** Gets the `return` edge label. */
|
||||
bindingset[m]
|
||||
bindingset[result]
|
||||
|
||||
@@ -2,5 +2,5 @@ classMethodCalls
|
||||
| test1.rb:58:1:58:8 | Use getMember("M1").getMember("C1").getReturn("m") |
|
||||
| test1.rb:59:1:59:8 | Use getMember("M2").getMember("C3").getReturn("m") |
|
||||
instanceMethodCalls
|
||||
| test1.rb:61:1:61:12 | Use getMember("M1").getMember("C1").instance.getReturn("m") |
|
||||
| test1.rb:62:1:62:12 | Use getMember("M2").getMember("C3").instance.getReturn("m") |
|
||||
| test1.rb:61:1:61:12 | Use getMember("M1").getMember("C1").getReturn("new").getReturn("m") |
|
||||
| test1.rb:62:1:62:12 | Use getMember("M2").getMember("C3").getReturn("new").getReturn("m") |
|
||||
|
||||
@@ -9,7 +9,7 @@ begin
|
||||
rescue AttributeError => e #$ use=getMember("AttributeError")
|
||||
Kernel.print(e) #$ use=getMember("Kernel").getReturn("print")
|
||||
end
|
||||
Unknown.new.run #$ use=getMember("Unknown").instance.getReturn("run")
|
||||
Unknown.new.run #$ use=getMember("Unknown").getReturn("new").getReturn("run")
|
||||
Foo::Bar::Baz #$ use=getMember("Foo").getMember("Bar").getMember("Baz")
|
||||
|
||||
Const = [1, 2, 3] #$ use=getMember("Array").getReturn("[]")
|
||||
|
||||
Reference in New Issue
Block a user