mirror of
https://github.com/securego/gosec.git
synced 2024-11-06 03:55:50 +00:00
Merge pull request #211 from WillAbides/commandcontext
Make G204 look for CommandContext calls
This commit is contained in:
commit
5ba647528a
2 changed files with 14 additions and 0 deletions
|
@ -58,6 +58,7 @@ func (r *subprocess) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
|
|||
func NewSubproc(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
|
||||
rule := &subprocess{gosec.MetaData{ID: id}, gosec.NewCallList()}
|
||||
rule.Add("os/exec", "Command")
|
||||
rule.Add("os/exec", "CommandContext")
|
||||
rule.Add("syscall", "Exec")
|
||||
return rule, []ast.Node{(*ast.CallExpr)(nil)}
|
||||
}
|
||||
|
|
|
@ -408,6 +408,19 @@ 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"
|
||||
|
|
Loading…
Reference in a new issue