diff --git a/ql/test/library-tests/modules/ancestors.expected b/ql/test/library-tests/modules/ancestors.expected index a8b8d7d9561..eff927ec222 100644 --- a/ql/test/library-tests/modules/ancestors.expected +++ b/ql/test/library-tests/modules/ancestors.expected @@ -39,6 +39,16 @@ #-----| Rational #-----| super -> Numeric +calls.rb: +# 15| M + +# 29| C +#-----| super -> Object +#-----| include -> M + +# 51| D +#-----| super -> C + hello.rb: # 1| EnglishWords diff --git a/ql/test/library-tests/modules/callgraph.expected b/ql/test/library-tests/modules/callgraph.expected new file mode 100644 index 00000000000..bb931ddeac6 --- /dev/null +++ b/ql/test/library-tests/modules/callgraph.expected @@ -0,0 +1,45 @@ +getTarget +| calls.rb:5:1:5:3 | call to foo | calls.rb:1:1:3:3 | foo | +| calls.rb:11:1:11:8 | call to bar | calls.rb:7:1:9:3 | bar | +| calls.rb:13:1:13:8 | call to foo | calls.rb:1:1:3:3 | foo | +| calls.rb:22:5:22:15 | call to singleton_m | calls.rb:17:5:17:29 | singleton_m | +| calls.rb:23:5:23:20 | call to singleton_m | calls.rb:17:5:17:29 | singleton_m | +| calls.rb:27:1:27:13 | call to singleton_m | calls.rb:17:5:17:29 | singleton_m | +| calls.rb:38:9:38:18 | call to instance_m | calls.rb:16:5:16:23 | instance_m | +| calls.rb:39:9:39:23 | call to instance_m | calls.rb:16:5:16:23 | instance_m | +| calls.rb:47:1:47:5 | call to baz | calls.rb:37:5:43:7 | baz | +| calls.rb:49:1:49:12 | call to instance_m | calls.rb:16:5:16:23 | instance_m | +| calls.rb:53:9:53:13 | call to super | calls.rb:37:5:43:7 | baz | +| calls.rb:58:1:58:5 | call to baz | calls.rb:52:5:54:7 | baz | +| calls.rb:60:1:60:12 | call to instance_m | calls.rb:16:5:16:23 | instance_m | +| hello.rb:14:16:14:20 | call to hello | hello.rb:2:5:4:7 | hello | +| hello.rb:20:16:20:20 | call to super | hello.rb:13:5:15:7 | message | +| hello.rb:20:30:20:34 | call to world | hello.rb:5:5:7:7 | world | +unresolvedCall +| calls.rb:2:5:2:14 | call to puts | +| calls.rb:8:5:8:14 | call to puts | +| calls.rb:19:5:19:14 | call to instance_m | +| calls.rb:20:5:20:19 | call to instance_m | +| calls.rb:26:1:26:12 | call to instance_m | +| calls.rb:30:5:30:13 | call to include | +| calls.rb:31:5:31:14 | call to instance_m | +| calls.rb:32:5:32:19 | call to instance_m | +| calls.rb:34:5:34:15 | call to singleton_m | +| calls.rb:35:5:35:20 | call to singleton_m | +| calls.rb:41:9:41:19 | call to singleton_m | +| calls.rb:42:9:42:24 | call to singleton_m | +| calls.rb:46:5:46:9 | call to new | +| calls.rb:48:1:48:13 | call to singleton_m | +| calls.rb:57:5:57:9 | call to new | +| calls.rb:59:1:59:13 | call to singleton_m | +| hello.rb:12:5:12:24 | call to include | +| modules.rb:12:5:12:26 | call to puts | +| modules.rb:22:3:22:19 | call to puts | +| modules.rb:33:3:33:25 | call to puts | +| modules.rb:44:3:44:19 | call to puts | +| modules.rb:55:3:55:30 | call to puts | +| modules.rb:89:3:89:16 | call to include | +| modules.rb:90:3:90:38 | call to module_eval | +| modules.rb:90:24:90:36 | call to prepend | +| modules.rb:96:3:96:14 | call to include | +| modules.rb:102:3:102:16 | call to prepend | diff --git a/ql/test/library-tests/modules/callgraph.ql b/ql/test/library-tests/modules/callgraph.ql new file mode 100644 index 00000000000..5dac6d2ccbd --- /dev/null +++ b/ql/test/library-tests/modules/callgraph.ql @@ -0,0 +1,6 @@ +import ruby +import codeql_ruby.dataflow.internal.DataFlowDispatch + +query DataFlowCallable getTarget(DataFlowCall call) { result = call.getTarget() } + +query predicate unresolvedCall(DataFlowCall call) { not exists(call.getTarget()) } diff --git a/ql/test/library-tests/modules/calls.rb b/ql/test/library-tests/modules/calls.rb new file mode 100644 index 00000000000..2a8fcce7235 --- /dev/null +++ b/ql/test/library-tests/modules/calls.rb @@ -0,0 +1,60 @@ +def foo + puts "foo" +end + +foo + +def self.bar + puts "bar" +end + +self.bar + +self.foo + +module M + def instance_m; end + def self.singleton_m; end + + instance_m # NoMethodError + self.instance_m # NoMethodError + + singleton_m + self.singleton_m +end + +M.instance_m # NoMethodError +M.singleton_m + +class C + include M + instance_m # NoMethodError + self.instance_m # NoMethodError + + singleton_m # NoMethodError + self.singleton_m # NoMethodError + + def baz + instance_m + self.instance_m + + singleton_m # NoMethodError + self.singleton_m # NoMethodError + end +end + +c = C.new +c.baz +c.singleton_m # NoMethodError +c.instance_m + +class D < C + def baz + super + end +end + +d = D.new +d.baz +d.singleton_m # NoMethodError +d.instance_m \ No newline at end of file diff --git a/ql/test/library-tests/modules/methods.expected b/ql/test/library-tests/modules/methods.expected index 1a745517cfd..ea1c7b6a0af 100644 --- a/ql/test/library-tests/modules/methods.expected +++ b/ql/test/library-tests/modules/methods.expected @@ -1,4 +1,8 @@ getMethod +| calls.rb:15:1:24:3 | M | instance_m | calls.rb:16:5:16:23 | instance_m | +| calls.rb:29:1:44:3 | C | baz | calls.rb:37:5:43:7 | baz | +| calls.rb:51:1:55:3 | D | baz | calls.rb:52:5:54:7 | baz | +| file://:0:0:0:0 | Object | foo | calls.rb:1:1:3:3 | foo | | hello.rb:1:1:8:3 | EnglishWords | hello | hello.rb:2:5:4:7 | hello | | hello.rb:1:1:8:3 | EnglishWords | world | hello.rb:5:5:7:7 | world | | hello.rb:11:1:16:3 | Greeting | message | hello.rb:13:5:15:7 | message | @@ -10,11 +14,32 @@ getMethod | modules.rb:37:1:46:3 | Bar | method_a | modules.rb:38:3:39:5 | method_a | | modules.rb:37:1:46:3 | Bar | method_b | modules.rb:41:3:42:5 | method_b | lookupMethod +| calls.rb:15:1:24:3 | M | instance_m | calls.rb:16:5:16:23 | instance_m | +| calls.rb:29:1:44:3 | C | baz | calls.rb:37:5:43:7 | baz | +| calls.rb:29:1:44:3 | C | foo | calls.rb:1:1:3:3 | foo | +| calls.rb:29:1:44:3 | C | instance_m | calls.rb:16:5:16:23 | instance_m | +| calls.rb:51:1:55:3 | D | baz | calls.rb:52:5:54:7 | baz | +| calls.rb:51:1:55:3 | D | foo | calls.rb:1:1:3:3 | foo | +| calls.rb:51:1:55:3 | D | instance_m | calls.rb:16:5:16:23 | instance_m | +| file://:0:0:0:0 | Array | foo | calls.rb:1:1:3:3 | foo | +| file://:0:0:0:0 | Boolean | foo | calls.rb:1:1:3:3 | foo | +| file://:0:0:0:0 | Class | foo | calls.rb:1:1:3:3 | foo | +| file://:0:0:0:0 | Complex | foo | calls.rb:1:1:3:3 | foo | +| file://:0:0:0:0 | Float | foo | calls.rb:1:1:3:3 | foo | +| file://:0:0:0:0 | Hash | foo | calls.rb:1:1:3:3 | foo | +| file://:0:0:0:0 | Integer | foo | calls.rb:1:1:3:3 | foo | +| file://:0:0:0:0 | Module | foo | calls.rb:1:1:3:3 | foo | +| file://:0:0:0:0 | NilClass | foo | calls.rb:1:1:3:3 | foo | +| file://:0:0:0:0 | Numeric | foo | calls.rb:1:1:3:3 | foo | +| file://:0:0:0:0 | Object | foo | calls.rb:1:1:3:3 | foo | +| file://:0:0:0:0 | Rational | foo | calls.rb:1:1:3:3 | foo | | hello.rb:1:1:8:3 | EnglishWords | hello | hello.rb:2:5:4:7 | hello | | hello.rb:1:1:8:3 | EnglishWords | world | hello.rb:5:5:7:7 | world | +| hello.rb:11:1:16:3 | Greeting | foo | calls.rb:1:1:3:3 | foo | | hello.rb:11:1:16:3 | Greeting | hello | hello.rb:2:5:4:7 | hello | | hello.rb:11:1:16:3 | Greeting | message | hello.rb:13:5:15:7 | message | | hello.rb:11:1:16:3 | Greeting | world | hello.rb:5:5:7:7 | world | +| hello.rb:18:1:22:3 | HelloWorld | foo | calls.rb:1:1:3:3 | foo | | hello.rb:18:1:22:3 | HelloWorld | hello | hello.rb:2:5:4:7 | hello | | hello.rb:18:1:22:3 | HelloWorld | message | hello.rb:19:5:21:7 | message | | hello.rb:18:1:22:3 | HelloWorld | world | hello.rb:5:5:7:7 | world | @@ -22,5 +47,14 @@ lookupMethod | modules.rb:4:1:24:3 | Foo | method_in_foo | modules.rb:16:3:17:5 | method_in_foo | | modules.rb:5:3:14:5 | Foo::Bar | method_in_another_definition_of_foo_bar | modules.rb:52:3:53:5 | method_in_another_definition_of_foo_bar | | modules.rb:5:3:14:5 | Foo::Bar | method_in_foo_bar | modules.rb:9:5:10:7 | method_in_foo_bar | +| modules.rb:6:5:7:7 | Foo::Bar::ClassInFooBar | foo | calls.rb:1:1:3:3 | foo | +| modules.rb:19:3:20:5 | Foo::ClassInFoo | foo | calls.rb:1:1:3:3 | foo | +| modules.rb:30:3:31:5 | Foo::ClassInAnotherDefinitionOfFoo | foo | calls.rb:1:1:3:3 | foo | +| modules.rb:37:1:46:3 | Bar | foo | calls.rb:1:1:3:3 | foo | | modules.rb:37:1:46:3 | Bar | method_a | modules.rb:38:3:39:5 | method_a | | modules.rb:37:1:46:3 | Bar | method_b | modules.rb:41:3:42:5 | method_b | +| modules.rb:49:3:50:5 | Foo::Bar::ClassInAnotherDefinitionOfFooBar | foo | calls.rb:1:1:3:3 | foo | +| modules.rb:66:5:67:7 | Test::Foo1::Bar | foo | calls.rb:1:1:3:3 | foo | +| modules.rb:72:5:73:7 | Test::Foo2::Foo2::Bar | foo | calls.rb:1:1:3:3 | foo | +| modules.rb:112:1:113:3 | YY | foo | calls.rb:1:1:3:3 | foo | +| modules.rb:116:7:117:9 | XX::YY | foo | calls.rb:1:1:3:3 | foo | diff --git a/ql/test/library-tests/modules/modules.expected b/ql/test/library-tests/modules/modules.expected index f05d6e38a3a..ca78ce9298d 100644 --- a/ql/test/library-tests/modules/modules.expected +++ b/ql/test/library-tests/modules/modules.expected @@ -1,4 +1,7 @@ getModule +| calls.rb:15:1:24:3 | M | +| calls.rb:29:1:44:3 | C | +| calls.rb:51:1:55:3 | D | | file://:0:0:0:0 | Array | | file://:0:0:0:0 | BasicObject | | file://:0:0:0:0 | Boolean | @@ -47,6 +50,10 @@ getModule | modules.rb:116:7:117:9 | XX::YY | | modules.rb:120:1:121:3 | Test::Foo1::Bar::Baz | getADeclaration +| calls.rb:15:1:24:3 | M | calls.rb:15:1:24:3 | M | +| calls.rb:29:1:44:3 | C | calls.rb:29:1:44:3 | C | +| calls.rb:51:1:55:3 | D | calls.rb:51:1:55:3 | D | +| file://:0:0:0:0 | Object | calls.rb:1:1:60:12 | calls.rb | | file://:0:0:0:0 | Object | hello.rb:1:1:22:3 | hello.rb | | file://:0:0:0:0 | Object | modules.rb:1:1:122:1 | modules.rb | | hello.rb:1:1:8:3 | EnglishWords | hello.rb:1:1:8:3 | EnglishWords | @@ -86,6 +93,8 @@ getADeclaration | modules.rb:116:7:117:9 | XX::YY | modules.rb:116:7:117:9 | YY | | modules.rb:120:1:121:3 | Test::Foo1::Bar::Baz | modules.rb:120:1:121:3 | Baz | getSuperClass +| calls.rb:29:1:44:3 | C | file://:0:0:0:0 | Object | +| calls.rb:51:1:55:3 | D | calls.rb:29:1:44:3 | C | | file://:0:0:0:0 | Array | file://:0:0:0:0 | Object | | file://:0:0:0:0 | Boolean | file://:0:0:0:0 | Object | | file://:0:0:0:0 | Class | file://:0:0:0:0 | Object | @@ -112,6 +121,7 @@ getSuperClass getAPrependedModule | modules.rb:101:1:105:3 | PrependTest | modules.rb:63:1:81:3 | Test | getAnIncludedModule +| calls.rb:29:1:44:3 | C | calls.rb:15:1:24:3 | M | | file://:0:0:0:0 | Object | file://:0:0:0:0 | Kernel | | hello.rb:11:1:16:3 | Greeting | hello.rb:1:1:8:3 | EnglishWords | | modules.rb:88:1:93:3 | IncludeTest | modules.rb:63:1:81:3 | Test | diff --git a/ql/test/library-tests/modules/superclasses.expected b/ql/test/library-tests/modules/superclasses.expected index 91bd3ef411a..9c7ce30544a 100644 --- a/ql/test/library-tests/modules/superclasses.expected +++ b/ql/test/library-tests/modules/superclasses.expected @@ -38,6 +38,15 @@ #-----| Rational #-----| -> Numeric +calls.rb: +# 15| M + +# 29| C +#-----| -> Object + +# 51| D +#-----| -> C + hello.rb: # 1| EnglishWords