From d7ec2fce7aa29580a4aaf6b4cb13e6cf005a8686 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Sun, 3 Jun 2018 16:43:28 -0500 Subject: [PATCH] add CommandContext as subprocess launcher --- rules/subproc.go | 1 + testutils/source.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/rules/subproc.go b/rules/subproc.go index 8c0f675..b665f88 100644 --- a/rules/subproc.go +++ b/rules/subproc.go @@ -58,6 +58,7 @@ func (r *subprocess) Match(n ast.Node, c *gas.Context) (*gas.Issue, error) { func NewSubproc(id string, conf gas.Config) (gas.Rule, []ast.Node) { rule := &subprocess{gas.MetaData{ID: id}, gas.NewCallList()} rule.Add("os/exec", "Command") + rule.Add("os/exec", "CommandContext") rule.Add("syscall", "Exec") return rule, []ast.Node{(*ast.CallExpr)(nil)} } diff --git a/testutils/source.go b/testutils/source.go index a0ba5bf..4a1448a 100644 --- a/testutils/source.go +++ b/testutils/source.go @@ -408,6 +408,20 @@ func main() { log.Printf("Command finished with error: %v", err) }`, 1}, {` package main +import ( + "log" + "os/exec" + "context" +) +func main() { + err := exec.CommandContext(context.Background(), "sleep", "5").Run() + if err != nil { + log.Fatal(err) + } + log.Printf("Command finished with error: %v", err) +} +}`, 1}, {` +package main import ( "log" "os"