Skip to content

Commit 9d13a1f

Browse files
committed
Ruby: Add model for Process.spawn
1 parent d184756 commit 9d13a1f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Provides modeling for the `Process` library.
3+
*/
4+
5+
private import codeql.ruby.Concepts
6+
private import codeql.ruby.DataFlow
7+
private import codeql.ruby.controlflow.CfgNodes
8+
private import codeql.ruby.frameworks.core.Kernel
9+
10+
/**
11+
* Provides modeling for the `Process` library.
12+
*/
13+
module Process {
14+
/**
15+
* A call to `Process.spawn`.
16+
* ```rb
17+
* Process.spawn("tar xf ruby-2.0.0-p195.tar.bz2")
18+
* Process.spawn({"ENV" => "VAR"}, "echo", "hi")
19+
* ```
20+
*/
21+
class SpawnCall extends SystemCommandExecution::Range instanceof DataFlow::CallNode {
22+
SpawnCall() { this = DataFlow::getConstant(["Process", "PTY"]).getAMethodCall("spawn") }
23+
24+
// The command can be argument 0 or 1
25+
// Options can be specified after the command, and we want to exclude those.
26+
override DataFlow::Node getAnArgument() {
27+
result = super.getArgument([0, 1]) and not result.asExpr() instanceof ExprNodes::PairCfgNode
28+
}
29+
30+
override predicate isShellInterpreted(DataFlow::Node arg) {
31+
// Process.spawn invokes a subshell if you provide a single string as argument
32+
super.getNumberOfArguments() = 1 and arg = this.getAnArgument()
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)