Use dataflow to find method call targets

This includes both local and non-local methods, and is also simpler than
the previous definition.
This commit is contained in:
Harry Maclean
2021-08-09 12:03:58 +01:00
parent cd3192e8f1
commit 91d56cd802
2 changed files with 6 additions and 5 deletions

View File

@@ -13,12 +13,13 @@
import ruby
import codeql_ruby.ast.internal.Module
import codeql_ruby.dataflow.SSA
import codeql_ruby.dataflow.internal.DataFlowDispatch
from DefLoc loc, Expr src, Expr target, string kind
where
ConstantDefLoc(src, target) = loc and kind = "constant"
or
LocalMethodLoc(src, target) = loc and kind = "method"
MethodLoc(src, target) = loc and kind = "method"
or
LocalVariableLoc(src, target) = loc and kind = "variable"
or
@@ -36,10 +37,9 @@ select src, target, kind
newtype DefLoc =
/** A constant, module or class. */
ConstantDefLoc(ConstantReadAccess read, ConstantWriteAccess write) { write = definitionOf(read) } or
/** A call to a method that is defined in the same class as the call. */
LocalMethodLoc(MethodCall call, Method meth) {
meth = lookupMethod(call.getEnclosingModule().getModule(), call.getMethodName()) and
call.getReceiver() instanceof Self
/** A method call. */
MethodLoc(MethodCall call, Method meth) {
exists(DataFlowCall c | c.getExpr() = call and c.getTarget() = meth)
} or
/** A local variable. */
LocalVariableLoc(VariableReadAccess read, VariableWriteAccess write) {

View File

@@ -6,6 +6,7 @@
| Definitions.rb:32:7:32:7 | y | Definitions.rb:31:10:31:10 | y | variable |
| Definitions.rb:36:7:36:7 | A | Definitions.rb:1:1:17:3 | A | constant |
| Definitions.rb:36:7:36:10 | B | Definitions.rb:4:3:16:5 | B | constant |
| Definitions.rb:36:7:36:18 | call to g | Definitions.rb:9:5:11:7 | g | method |
| Definitions.rb:36:18:36:18 | y | Definitions.rb:35:11:35:11 | y | variable |
| Definitions.rb:39:7:39:8 | @e | Definitions.rb:30:7:30:8 | @e | instance variable |
| Definitions.rb:41:7:41:9 | @@b | Definitions.rb:27:5:27:7 | @@b | class variable |