Skip to content

Commit 5ba6475

Browse files
author
Cosmin Cojocar
authored
Merge pull request #211 from WillAbides/commandcontext
Make G204 look for CommandContext calls
2 parents 2785f7a + 1f9d09d commit 5ba6475

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

rules/subproc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (r *subprocess) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
5858
func NewSubproc(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
5959
rule := &subprocess{gosec.MetaData{ID: id}, gosec.NewCallList()}
6060
rule.Add("os/exec", "Command")
61+
rule.Add("os/exec", "CommandContext")
6162
rule.Add("syscall", "Exec")
6263
return rule, []ast.Node{(*ast.CallExpr)(nil)}
6364
}

testutils/source.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,19 @@ func main() {
408408
log.Printf("Command finished with error: %v", err)
409409
}`, 1}, {`
410410
package main
411+
import (
412+
"log"
413+
"os/exec"
414+
"context"
415+
)
416+
func main() {
417+
err := exec.CommandContext(context.Background(), "sleep", "5").Run()
418+
if err != nil {
419+
log.Fatal(err)
420+
}
421+
log.Printf("Command finished with error: %v", err)
422+
}`, 1}, {`
423+
package main
411424
import (
412425
"log"
413426
"os"

0 commit comments

Comments
 (0)