Skip to content

Commit

Permalink
chore: disallow use of exec.Command
Browse files Browse the repository at this point in the history
exec.Command requires different behavior based on the user's OS, which our helpers already handle.
  • Loading branch information
Piccirello committed Jul 10, 2023
1 parent d211198 commit 19fe020
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func Cwd() string {

// RunCommand runs the specified command
func RunCommand(command []string, env []string, inFile *os.File, outFile *os.File, errFile *os.File, forwardSignals bool) (*exec.Cmd, error) {
cmd := exec.Command(command[0], command[1:]...) // #nosec G204
cmd := exec.Command(command[0], command[1:]...) // #nosec G204 nosemgrep: semgrep_configs.prohibit-exec-command
cmd.Env = env
cmd.Stdin = inFile
cmd.Stdout = outFile
Expand All @@ -132,7 +132,7 @@ func RunCommandString(command string, env []string, inFile *os.File, outFile *os
}
}
}
cmd := exec.Command(shell[0], shell[1], command) // #nosec G204
cmd := exec.Command(shell[0], shell[1], command) // #nosec G204 nosemgrep: semgrep_configs.prohibit-exec-command
cmd.Env = env
cmd.Stdin = inFile
cmd.Stdout = outFile
Expand Down
9 changes: 9 additions & 0 deletions semgrep_configs/exec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rules:
- id: prohibit-exec-command
languages:
- go
message: >
Use utils.RunCommand or utils.RunCommandString to ensure exec is os agnostic.
pattern-either:
- pattern: exec.Command
severity: ERROR

0 comments on commit 19fe020

Please sign in to comment.