add CommandContext as subprocess launcher

This commit is contained in:
Will Roden 2018-06-03 16:43:28 -05:00
parent 4ae8c95b40
commit d7ec2fce7a
2 changed files with 15 additions and 0 deletions

View file

@ -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)}
}

View file

@ -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"