Ruby: split tests to match stdlib changes

This commit is contained in:
Harry Maclean
2022-02-04 17:19:53 +13:00
parent eb4f333c25
commit 546bfcb8ea
21 changed files with 195 additions and 174 deletions

View File

@@ -0,0 +1,8 @@
subshellLiteralExecutions
| Core.rb:1:1:1:10 | `echo foo` |
| Core.rb:2:1:2:12 | `echo foo` |
| Core.rb:3:1:3:12 | `echo foo` |
| Core.rb:4:1:4:12 | `echo foo` |
| Core.rb:5:1:5:12 | `echo foo` |
subshellHeredocExecutions
| Core.rb:7:1:7:7 | <<`EOF` |

View File

@@ -0,0 +1,6 @@
import codeql.ruby.frameworks.Core
import codeql.ruby.DataFlow
query predicate subshellLiteralExecutions(SubshellLiteralExecution e) { any() }
query predicate subshellHeredocExecutions(SubshellHeredocExecution e) { any() }

View File

@@ -21,6 +21,4 @@ class Foo
end
Foo.new.send("exit", 1)
Foo.new.instance_eval("self.class", "file.rb", 3)
Foo.class_eval("def foo; 1; end", "file.rb", 1)
Foo.module_eval("def bar; 1; end", "other_file.rb", 2)

View File

@@ -1,111 +0,0 @@
subshellLiteralExecutions
| CommandExecution.rb:1:1:1:10 | `echo foo` |
| CommandExecution.rb:2:1:2:12 | `echo foo` |
| CommandExecution.rb:3:1:3:12 | `echo foo` |
| CommandExecution.rb:4:1:4:12 | `echo foo` |
| CommandExecution.rb:5:1:5:12 | `echo foo` |
subshellHeredocExecutions
| CommandExecution.rb:67:1:67:7 | <<`EOF` |
kernelSystemCallExecutions
| CommandExecution.rb:7:1:7:18 | call to system |
| CommandExecution.rb:8:1:8:21 | call to system |
| CommandExecution.rb:9:1:9:31 | call to system |
| CommandExecution.rb:11:1:11:36 | call to system |
| CommandExecution.rb:12:1:12:39 | call to system |
| CommandExecution.rb:13:1:13:49 | call to system |
| CommandExecution.rb:15:1:15:41 | call to system |
| CommandExecution.rb:16:1:16:44 | call to system |
| CommandExecution.rb:17:1:17:54 | call to system |
| CommandExecution.rb:19:1:19:59 | call to system |
| CommandExecution.rb:20:1:20:62 | call to system |
| CommandExecution.rb:21:1:21:72 | call to system |
| app/graphql/mutations/dummy.rb:10:7:10:33 | call to system |
| app/graphql/resolvers/dummy_resolver.rb:11:7:11:33 | call to system |
| app/graphql/types/query_type.rb:11:7:11:30 | call to system |
| app/graphql/types/query_type.rb:19:7:19:35 | call to system |
| app/graphql/types/query_type.rb:20:7:20:30 | call to system |
| app/graphql/types/query_type.rb:28:7:28:40 | call to system |
| app/graphql/types/query_type.rb:37:7:37:28 | call to system |
| app/graphql/types/query_type.rb:38:7:38:35 | call to system |
| app/graphql/types/query_type.rb:43:7:43:27 | call to system |
kernelExecCallExecutions
| CommandExecution.rb:23:1:23:16 | call to exec |
| CommandExecution.rb:24:1:24:19 | call to exec |
| CommandExecution.rb:25:1:25:29 | call to exec |
| CommandExecution.rb:27:1:27:34 | call to exec |
| CommandExecution.rb:28:1:28:37 | call to exec |
| CommandExecution.rb:29:1:29:47 | call to exec |
| CommandExecution.rb:31:1:31:39 | call to exec |
| CommandExecution.rb:32:1:32:42 | call to exec |
| CommandExecution.rb:33:1:33:52 | call to exec |
| CommandExecution.rb:35:1:35:57 | call to exec |
| CommandExecution.rb:36:1:36:60 | call to exec |
| CommandExecution.rb:37:1:37:70 | call to exec |
kernelSpawnCallExecutions
| CommandExecution.rb:39:1:39:17 | call to spawn |
| CommandExecution.rb:40:1:40:20 | call to spawn |
| CommandExecution.rb:41:1:41:30 | call to spawn |
| CommandExecution.rb:43:1:43:35 | call to spawn |
| CommandExecution.rb:44:1:44:38 | call to spawn |
| CommandExecution.rb:45:1:45:48 | call to spawn |
| CommandExecution.rb:47:1:47:40 | call to spawn |
| CommandExecution.rb:48:1:48:43 | call to spawn |
| CommandExecution.rb:49:1:49:53 | call to spawn |
| CommandExecution.rb:51:1:51:58 | call to spawn |
| CommandExecution.rb:52:1:52:61 | call to spawn |
| CommandExecution.rb:53:1:53:71 | call to spawn |
open3CallExecutions
| CommandExecution.rb:55:1:55:24 | call to popen3 |
| CommandExecution.rb:56:1:56:24 | call to popen2 |
| CommandExecution.rb:57:1:57:25 | call to popen2e |
| CommandExecution.rb:58:1:58:26 | call to capture3 |
| CommandExecution.rb:59:1:59:26 | call to capture2 |
| CommandExecution.rb:60:1:60:27 | call to capture2e |
open3PipelineCallExecutions
| CommandExecution.rb:61:1:61:41 | call to pipeline_rw |
| CommandExecution.rb:62:1:62:40 | call to pipeline_r |
| CommandExecution.rb:63:1:63:40 | call to pipeline_w |
| CommandExecution.rb:64:1:64:44 | call to pipeline_start |
| CommandExecution.rb:65:1:65:38 | call to pipeline |
evalCallCodeExecutions
| Eval.rb:3:1:3:43 | call to eval | Eval.rb:3:6:3:22 | "raise \\"error\\"" |
sendCallCodeExecutions
| Eval.rb:4:1:4:22 | call to send | Eval.rb:4:6:4:12 | "raise" |
| Eval.rb:7:1:7:19 | call to send | Eval.rb:7:8:7:13 | "push" |
instanceEvalCallCodeExecutions
| Eval.rb:24:1:24:49 | call to instance_eval | Eval.rb:24:23:24:34 | "self.class" |
classEvalCallCodeExecutions
| Eval.rb:25:1:25:47 | call to class_eval | Eval.rb:25:16:25:32 | "def foo; 1; end" |
moduleEvalCallCodeExecutions
| Eval.rb:26:1:26:54 | call to module_eval | Eval.rb:26:17:26:33 | "def bar; 1; end" |
loggerLoggingCallInputs
| Logging.rb:5:3:5:23 | call to progname= | Logging.rb:5:27:5:38 | "LoggerTest" |
| Logging.rb:15:5:15:21 | call to debug | Logging.rb:15:19:15:21 | msg |
| Logging.rb:20:5:22:7 | call to error | Logging.rb:21:7:21:15 | ... + ... |
| Logging.rb:27:5:27:21 | call to fatal | Logging.rb:27:19:27:21 | msg |
| Logging.rb:32:5:32:20 | call to warn | Logging.rb:32:18:32:20 | msg |
| Logging.rb:37:5:37:43 | call to unknown | Logging.rb:37:21:37:34 | "unknown prog" |
| Logging.rb:37:5:37:43 | call to unknown | Logging.rb:37:39:37:41 | msg |
| Logging.rb:42:5:48:7 | call to info | Logging.rb:43:7:47:9 | if ... |
| Logging.rb:54:5:54:44 | ... << ... | Logging.rb:54:21:54:44 | ( ... ) |
| Logging.rb:58:5:58:46 | call to add | Logging.rb:58:38:58:44 | "block" |
| Logging.rb:60:5:60:64 | call to add | Logging.rb:60:36:60:38 | nil |
| Logging.rb:60:5:60:64 | call to add | Logging.rb:60:41:60:51 | "progname1" |
| Logging.rb:60:5:60:64 | call to add | Logging.rb:60:56:60:62 | "block" |
| Logging.rb:63:5:63:63 | call to add | Logging.rb:63:36:63:45 | "message1" |
| Logging.rb:64:5:64:76 | call to add | Logging.rb:64:36:64:45 | "message2" |
| Logging.rb:64:5:64:76 | call to add | Logging.rb:64:48:64:58 | "progname2" |
| Logging.rb:68:5:68:46 | call to log | Logging.rb:68:38:68:44 | "block" |
| Logging.rb:70:5:70:64 | call to log | Logging.rb:70:36:70:38 | nil |
| Logging.rb:70:5:70:64 | call to log | Logging.rb:70:41:70:51 | "progname1" |
| Logging.rb:70:5:70:64 | call to log | Logging.rb:70:56:70:62 | "block" |
| Logging.rb:73:5:73:63 | call to log | Logging.rb:73:36:73:45 | "message1" |
| Logging.rb:74:5:74:76 | call to log | Logging.rb:74:36:74:45 | "message2" |
| Logging.rb:74:5:74:76 | call to log | Logging.rb:74:48:74:58 | "progname2" |
moduleConstGetCallCodeExecutions
| const_get.rb:1:1:1:24 | call to const_get | const_get.rb:1:18:1:23 | "Math" |
| const_get.rb:2:1:2:28 | call to const_get | const_get.rb:2:22:2:27 | "Math" |
| const_get.rb:3:1:3:20 | call to const_get | const_get.rb:3:16:3:19 | "PI" |
| const_get.rb:4:1:4:19 | call to const_get | const_get.rb:4:16:4:18 | :PI |
| const_get.rb:22:1:22:33 | call to const_get | const_get.rb:22:18:22:32 | "Foo::Baz::VAL" |
| const_get.rb:23:1:23:25 | call to const_get | const_get.rb:23:15:23:24 | "Bar::VAL" |

View File

@@ -1,38 +0,0 @@
import codeql.ruby.frameworks.StandardLibrary
import codeql.ruby.DataFlow
query predicate subshellLiteralExecutions(SubshellLiteralExecution e) { any() }
query predicate subshellHeredocExecutions(SubshellHeredocExecution e) { any() }
query predicate kernelSystemCallExecutions(KernelSystemCall c) { any() }
query predicate kernelExecCallExecutions(KernelExecCall c) { any() }
query predicate kernelSpawnCallExecutions(KernelSpawnCall c) { any() }
query predicate open3CallExecutions(Open3Call c) { any() }
query predicate open3PipelineCallExecutions(Open3PipelineCall c) { any() }
query DataFlow::Node evalCallCodeExecutions(EvalCallCodeExecution e) { result = e.getCode() }
query DataFlow::Node sendCallCodeExecutions(SendCallCodeExecution e) { result = e.getCode() }
query DataFlow::Node instanceEvalCallCodeExecutions(InstanceEvalCallCodeExecution e) {
result = e.getCode()
}
query DataFlow::Node classEvalCallCodeExecutions(ClassEvalCallCodeExecution e) {
result = e.getCode()
}
query DataFlow::Node moduleEvalCallCodeExecutions(ModuleEvalCallCodeExecution e) {
result = e.getCode()
}
query DataFlow::Node loggerLoggingCallInputs(LoggerLoggingCall c) { result = c.getAnInput() }
query DataFlow::Node moduleConstGetCallCodeExecutions(ModuleConstGetCallCodeExecution e) {
result = e.getCode()
}

View File

@@ -0,0 +1,9 @@
`echo foo`
%x(echo foo)
%x{echo foo}
%x[echo foo]
%x/echo foo/
<<`EOF`
echo foo
EOF

View File

@@ -0,0 +1 @@
| BasicObject.rb:1:1:1:49 | call to instance_eval | BasicObject.rb:1:23:1:34 | "self.class" |

View File

@@ -0,0 +1,6 @@
import codeql.ruby.frameworks.core.BasicObject::BasicObject
import codeql.ruby.DataFlow
query DataFlow::Node instanceEvalCallCodeExecutions(InstanceEvalCallCodeExecution e) {
result = e.getCode()
}

View File

@@ -0,0 +1 @@
Foo.new.instance_eval("self.class", "file.rb", 3)

View File

@@ -0,0 +1,44 @@
kernelSystemCallExecutions
| Kernel.rb:23:1:23:18 | call to system |
| Kernel.rb:24:1:24:21 | call to system |
| Kernel.rb:25:1:25:31 | call to system |
| Kernel.rb:27:1:27:36 | call to system |
| Kernel.rb:28:1:28:39 | call to system |
| Kernel.rb:29:1:29:49 | call to system |
| Kernel.rb:31:1:31:41 | call to system |
| Kernel.rb:32:1:32:44 | call to system |
| Kernel.rb:33:1:33:54 | call to system |
| Kernel.rb:35:1:35:59 | call to system |
| Kernel.rb:36:1:36:62 | call to system |
| Kernel.rb:37:1:37:72 | call to system |
kernelExecCallExecutions
| Kernel.rb:39:1:39:16 | call to exec |
| Kernel.rb:40:1:40:19 | call to exec |
| Kernel.rb:41:1:41:29 | call to exec |
| Kernel.rb:43:1:43:34 | call to exec |
| Kernel.rb:44:1:44:37 | call to exec |
| Kernel.rb:45:1:45:47 | call to exec |
| Kernel.rb:47:1:47:39 | call to exec |
| Kernel.rb:48:1:48:42 | call to exec |
| Kernel.rb:49:1:49:52 | call to exec |
| Kernel.rb:51:1:51:57 | call to exec |
| Kernel.rb:52:1:52:60 | call to exec |
| Kernel.rb:53:1:53:70 | call to exec |
kernelSpawnCallExecutions
| Kernel.rb:55:1:55:17 | call to spawn |
| Kernel.rb:56:1:56:20 | call to spawn |
| Kernel.rb:57:1:57:30 | call to spawn |
| Kernel.rb:59:1:59:35 | call to spawn |
| Kernel.rb:60:1:60:38 | call to spawn |
| Kernel.rb:61:1:61:48 | call to spawn |
| Kernel.rb:63:1:63:40 | call to spawn |
| Kernel.rb:64:1:64:43 | call to spawn |
| Kernel.rb:65:1:65:53 | call to spawn |
| Kernel.rb:67:1:67:58 | call to spawn |
| Kernel.rb:68:1:68:61 | call to spawn |
| Kernel.rb:69:1:69:71 | call to spawn |
sendCallCodeExecutions
| Kernel.rb:2:1:2:22 | call to send | Kernel.rb:2:6:2:12 | "raise" |
| Kernel.rb:5:1:5:19 | call to send | Kernel.rb:5:8:5:13 | "push" |
evalCallCodeExecutions
| Kernel.rb:1:1:1:43 | call to eval | Kernel.rb:1:6:1:22 | "raise \\"error\\"" |

View File

@@ -0,0 +1,12 @@
import codeql.ruby.frameworks.core.Kernel::Kernel
import codeql.ruby.DataFlow
query predicate kernelSystemCallExecutions(KernelSystemCall c) { any() }
query predicate kernelExecCallExecutions(KernelExecCall c) { any() }
query predicate kernelSpawnCallExecutions(KernelSpawnCall c) { any() }
query DataFlow::Node sendCallCodeExecutions(SendCallCodeExecution e) { result = e.getCode() }
query DataFlow::Node evalCallCodeExecutions(EvalCallCodeExecution e) { result = e.getCode() }

View File

@@ -1,8 +1,24 @@
`echo foo`
%x(echo foo)
%x{echo foo}
%x[echo foo]
%x/echo foo/
eval("raise \"error\"", binding, "file", 1)
send("raise", "error")
a = []
a.send("push", "1")
class Foo
def eval(x)
x + 1
end
def send(*args)
2
end
def run
eval("exit 1")
end
end
Foo.new.send("exit", 1)
system("echo foo")
system("echo", "foo")
@@ -52,22 +68,6 @@ spawn({"FOO" => "BAR"}, "echo foo", unsetenv_others: true)
spawn({"FOO" => "BAR"}, "echo", "foo", unsetenv_others: true)
spawn({"FOO" => "BAR"}, ["echo", "echo"], "foo", unsetenv_others: true)
Open3.popen3("echo foo")
Open3.popen2("echo foo")
Open3.popen2e("echo foo")
Open3.capture3("echo foo")
Open3.capture2("echo foo")
Open3.capture2e("echo foo")
Open3.pipeline_rw("echo foo", "grep bar")
Open3.pipeline_r("echo foo", "grep bar")
Open3.pipeline_w("echo foo", "grep bar")
Open3.pipeline_start("echo foo", "grep bar")
Open3.pipeline("echo foo", "grep bar")
<<`EOF`
echo foo
EOF
module MockSystem
def system(*args)
args
@@ -87,4 +87,4 @@ class Foo
end
end
UnknownModule.system("ls")
UnknownModule.system("ls")

View File

@@ -0,0 +1,11 @@
classEvalCallCodeExecutions
| Module.rb:29:1:29:47 | call to class_eval | Module.rb:29:16:29:32 | "def foo; 1; end" |
moduleEvalCallCodeExecutions
| Module.rb:30:1:30:54 | call to module_eval | Module.rb:30:17:30:33 | "def bar; 1; end" |
moduleConstGetCallCodeExecutions
| Module.rb:1:1:1:24 | call to const_get | Module.rb:1:18:1:23 | "Math" |
| Module.rb:2:1:2:28 | call to const_get | Module.rb:2:22:2:27 | "Math" |
| Module.rb:3:1:3:20 | call to const_get | Module.rb:3:16:3:19 | "PI" |
| Module.rb:4:1:4:19 | call to const_get | Module.rb:4:16:4:18 | :PI |
| Module.rb:22:1:22:33 | call to const_get | Module.rb:22:18:22:32 | "Foo::Baz::VAL" |
| Module.rb:23:1:23:25 | call to const_get | Module.rb:23:15:23:24 | "Bar::VAL" |

View File

@@ -0,0 +1,14 @@
import codeql.ruby.DataFlow
import codeql.ruby.frameworks.core.Module::Module
query DataFlow::Node classEvalCallCodeExecutions(ClassEvalCallCodeExecution e) {
result = e.getCode()
}
query DataFlow::Node moduleEvalCallCodeExecutions(ModuleEvalCallCodeExecution e) {
result = e.getCode()
}
query DataFlow::Node moduleConstGetCallCodeExecutions(ModuleConstGetCallCodeExecution e) {
result = e.getCode()
}

View File

@@ -24,4 +24,7 @@ Foo.const_get("Bar::VAL")
# Should not be identified as a use of Module#const_get
Foo::Bar.new.const_get 5
Foo::Baz.const_get 5
Foo::Baz.const_get 5
Foo.class_eval("def foo; 1; end", "file.rb", 1)
Foo.module_eval("def bar; 1; end", "other_file.rb", 2)

View File

@@ -0,0 +1,23 @@
| Logging.rb:5:3:5:23 | call to progname= | Logging.rb:5:27:5:38 | "LoggerTest" |
| Logging.rb:15:5:15:21 | call to debug | Logging.rb:15:19:15:21 | msg |
| Logging.rb:20:5:22:7 | call to error | Logging.rb:21:7:21:15 | ... + ... |
| Logging.rb:27:5:27:21 | call to fatal | Logging.rb:27:19:27:21 | msg |
| Logging.rb:32:5:32:20 | call to warn | Logging.rb:32:18:32:20 | msg |
| Logging.rb:37:5:37:43 | call to unknown | Logging.rb:37:21:37:34 | "unknown prog" |
| Logging.rb:37:5:37:43 | call to unknown | Logging.rb:37:39:37:41 | msg |
| Logging.rb:42:5:48:7 | call to info | Logging.rb:43:7:47:9 | if ... |
| Logging.rb:54:5:54:44 | ... << ... | Logging.rb:54:21:54:44 | ( ... ) |
| Logging.rb:58:5:58:46 | call to add | Logging.rb:58:38:58:44 | "block" |
| Logging.rb:60:5:60:64 | call to add | Logging.rb:60:36:60:38 | nil |
| Logging.rb:60:5:60:64 | call to add | Logging.rb:60:41:60:51 | "progname1" |
| Logging.rb:60:5:60:64 | call to add | Logging.rb:60:56:60:62 | "block" |
| Logging.rb:63:5:63:63 | call to add | Logging.rb:63:36:63:45 | "message1" |
| Logging.rb:64:5:64:76 | call to add | Logging.rb:64:36:64:45 | "message2" |
| Logging.rb:64:5:64:76 | call to add | Logging.rb:64:48:64:58 | "progname2" |
| Logging.rb:68:5:68:46 | call to log | Logging.rb:68:38:68:44 | "block" |
| Logging.rb:70:5:70:64 | call to log | Logging.rb:70:36:70:38 | nil |
| Logging.rb:70:5:70:64 | call to log | Logging.rb:70:41:70:51 | "progname1" |
| Logging.rb:70:5:70:64 | call to log | Logging.rb:70:56:70:62 | "block" |
| Logging.rb:73:5:73:63 | call to log | Logging.rb:73:36:73:45 | "message1" |
| Logging.rb:74:5:74:76 | call to log | Logging.rb:74:36:74:45 | "message2" |
| Logging.rb:74:5:74:76 | call to log | Logging.rb:74:48:74:58 | "progname2" |

View File

@@ -0,0 +1,4 @@
import codeql.ruby.frameworks.stdlib.Logger::Logger
import codeql.ruby.DataFlow
query DataFlow::Node loggerLoggingCallInputs(LoggerLoggingCall c) { result = c.getAnInput() }

View File

@@ -0,0 +1,13 @@
open3CallExecutions
| Open3.rb:1:1:1:24 | call to popen3 |
| Open3.rb:2:1:2:24 | call to popen2 |
| Open3.rb:3:1:3:25 | call to popen2e |
| Open3.rb:4:1:4:26 | call to capture3 |
| Open3.rb:5:1:5:26 | call to capture2 |
| Open3.rb:6:1:6:27 | call to capture2e |
open3PipelineCallExecutions
| Open3.rb:7:1:7:41 | call to pipeline_rw |
| Open3.rb:8:1:8:40 | call to pipeline_r |
| Open3.rb:9:1:9:40 | call to pipeline_w |
| Open3.rb:10:1:10:44 | call to pipeline_start |
| Open3.rb:11:1:11:38 | call to pipeline |

View File

@@ -0,0 +1,6 @@
import codeql.ruby.frameworks.stdlib.Open3::Open3
import codeql.ruby.DataFlow
query predicate open3CallExecutions(Open3Call c) { any() }
query predicate open3PipelineCallExecutions(Open3PipelineCall c) { any() }

View File

@@ -0,0 +1,11 @@
Open3.popen3("echo foo")
Open3.popen2("echo foo")
Open3.popen2e("echo foo")
Open3.capture3("echo foo")
Open3.capture2("echo foo")
Open3.capture2e("echo foo")
Open3.pipeline_rw("echo foo", "grep bar")
Open3.pipeline_r("echo foo", "grep bar")
Open3.pipeline_w("echo foo", "grep bar")
Open3.pipeline_start("echo foo", "grep bar")
Open3.pipeline("echo foo", "grep bar")