Skip to content

Commit a6bd677

Browse files
jmooringbep
authored andcommitted
common/hexec: Remove github.com/cli/safeexec
We began using the safeexec package in v0.79.1 to address GHSA-8j34-9876-pvfq. The vulnerability was addressed by the Go team in 1.19, so the safeexec package is no longer needed. Closes #13516
1 parent f34cdc3 commit a6bd677

File tree

5 files changed

+12
-27
lines changed

5 files changed

+12
-27
lines changed

Diff for: README.md

-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ github.com/bep/simplecobra="v0.5.0"
189189
github.com/bep/tmc="v0.5.1"
190190
github.com/cespare/xxhash/v2="v2.3.0"
191191
github.com/clbanning/mxj/v2="v2.7.0"
192-
github.com/cli/safeexec="v1.0.1"
193192
github.com/cpuguy83/go-md2man/v2="v2.0.4"
194193
github.com/disintegration/gift="v1.2.1"
195194
github.com/dlclark/regexp2="v1.11.5"

Diff for: common/hexec/exec.go

+5-18
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"sync"
2828

2929
"github.com/bep/logg"
30-
"github.com/cli/safeexec"
3130
"github.com/gohugoio/hugo/common/loggers"
3231
"github.com/gohugoio/hugo/common/maps"
3332
"github.com/gohugoio/hugo/config"
@@ -113,18 +112,6 @@ func IsNotFound(err error) bool {
113112
return errors.As(err, &notFoundErr)
114113
}
115114

116-
// SafeCommand is a wrapper around os/exec Command which uses a LookPath
117-
// implementation that does not search in current directory before looking in PATH.
118-
// See https://github.com/cli/safeexec and the linked issues.
119-
func SafeCommand(name string, arg ...string) (*exec.Cmd, error) {
120-
bin, err := safeexec.LookPath(name)
121-
if err != nil {
122-
return nil, err
123-
}
124-
125-
return exec.Command(bin, arg...), nil
126-
}
127-
128115
// Exec enforces a security policy for commands run via os/exec.
129116
type Exec struct {
130117
sc security.Config
@@ -197,7 +184,7 @@ func (e *Exec) Npx(name string, arg ...any) (Runner, error) {
197184
tryFuncs := map[binaryLocation]tryFunc{
198185
binaryLocationNodeModules: func() func(...any) (Runner, error) {
199186
nodeBinFilename := filepath.Join(e.workingDir, nodeModulesBinPath, name)
200-
_, err := safeexec.LookPath(nodeBinFilename)
187+
_, err := exec.LookPath(nodeBinFilename)
201188
if err != nil {
202189
return nil
203190
}
@@ -215,7 +202,7 @@ func (e *Exec) Npx(name string, arg ...any) (Runner, error) {
215202
}
216203
},
217204
binaryLocationPath: func() func(...any) (Runner, error) {
218-
if _, err := safeexec.LookPath(name); err != nil {
205+
if _, err := exec.LookPath(name); err != nil {
219206
return nil
220207
}
221208
return func(arg2 ...any) (Runner, error) {
@@ -346,7 +333,7 @@ func (c *commandeer) command(arg ...any) (*cmdWrapper, error) {
346333
bin = c.fullyQualifiedName
347334
} else {
348335
var err error
349-
bin, err = safeexec.LookPath(c.name)
336+
bin, err = exec.LookPath(c.name)
350337
if err != nil {
351338
return nil, &NotFoundError{
352339
name: c.name,
@@ -384,7 +371,7 @@ func InPath(binaryName string) bool {
384371
if strings.Contains(binaryName, "/") {
385372
panic("binary name should not contain any slash")
386373
}
387-
_, err := safeexec.LookPath(binaryName)
374+
_, err := exec.LookPath(binaryName)
388375
return err == nil
389376
}
390377

@@ -394,7 +381,7 @@ func LookPath(binaryName string) string {
394381
if strings.Contains(binaryName, "/") {
395382
panic("binary name should not contain any slash")
396383
}
397-
s, err := safeexec.LookPath(binaryName)
384+
s, err := exec.LookPath(binaryName)
398385
if err != nil {
399386
return ""
400387
}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ require (
2424
github.com/bep/tmc v0.5.1
2525
github.com/cespare/xxhash/v2 v2.3.0
2626
github.com/clbanning/mxj/v2 v2.7.0
27-
github.com/cli/safeexec v1.0.1
2827
github.com/disintegration/gift v1.2.1
2928
github.com/dustin/go-humanize v1.0.1
3029
github.com/evanw/esbuild v0.24.2
@@ -120,6 +119,7 @@ require (
120119
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4 // indirect
121120
github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 // indirect
122121
github.com/aws/smithy-go v1.22.2 // indirect
122+
github.com/cli/safeexec v1.0.1 // indirect
123123
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
124124
github.com/dlclark/regexp2 v1.11.4 // indirect
125125
github.com/felixge/httpsnoop v1.0.4 // indirect

Diff for: releaser/releaser.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import (
1919
"fmt"
2020
"log"
2121
"os"
22+
"os/exec"
2223
"path/filepath"
2324
"regexp"
2425
"strings"
2526

26-
"github.com/gohugoio/hugo/common/hexec"
2727
"github.com/gohugoio/hugo/common/hugo"
2828
)
2929

@@ -222,7 +222,7 @@ func (r *ReleaseHandler) replaceInFile(filename string, oldNew ...string) error
222222
}
223223

224224
func git(args ...string) (string, error) {
225-
cmd, _ := hexec.SafeCommand("git", args...)
225+
cmd := exec.Command("git", args...)
226226
out, err := cmd.CombinedOutput()
227227
if err != nil {
228228
return "", fmt.Errorf("git failed: %q: %q (%q)", err, out, args)

Diff for: scripts/fork_go_templates/main.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import (
44
"fmt"
55
"log"
66
"os"
7+
"os/exec"
78
"path/filepath"
89
"regexp"
910
"strings"
1011

11-
"github.com/gohugoio/hugo/common/hexec"
12-
1312
"github.com/gohugoio/hugo/common/hugio"
1413

1514
"github.com/spf13/afero"
@@ -208,7 +207,7 @@ func removeAll(expression, content string) string {
208207
}
209208

210209
func rewrite(filename, rule string) {
211-
cmf, _ := hexec.SafeCommand("gofmt", "-w", "-r", rule, filename)
210+
cmf := exec.Command("gofmt", "-w", "-r", rule, filename)
212211
out, err := cmf.CombinedOutput()
213212
if err != nil {
214213
log.Fatal("gofmt failed:", string(out))
@@ -217,15 +216,15 @@ func rewrite(filename, rule string) {
217216

218217
func goimports(dir string) {
219218
// Needs go install golang.org/x/tools/cmd/goimports@latest
220-
cmf, _ := hexec.SafeCommand("goimports", "-w", dir)
219+
cmf := exec.Command("goimports", "-w", dir)
221220
out, err := cmf.CombinedOutput()
222221
if err != nil {
223222
log.Fatal("goimports failed:", string(out))
224223
}
225224
}
226225

227226
func gofmt(dir string) {
228-
cmf, _ := hexec.SafeCommand("gofmt", "-w", dir)
227+
cmf := exec.Command("gofmt", "-w", dir)
229228
out, err := cmf.CombinedOutput()
230229
if err != nil {
231230
log.Fatal("gofmt failed:", string(out))

0 commit comments

Comments
 (0)