Skip to content

Commit fe37c9e

Browse files
all: replace all usages of os/exec with golang.org/x/sys/execabs
This change ensures that packages using exec.LookPath or exec.Command to find or run binaries do not accidentally run programs from the current directory when they mean to run programs from the system PATH instead. Change-Id: I5907aa630ff64012395a7eb472967a477d90f12e Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/949438 Reviewed-by: Katie Hockman <[email protected]> Reviewed-by: Russ Cox <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/tools/+/284773 Run-TryBot: Roland Shoemaker <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Roland Shoemaker <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent a46736d commit fe37c9e

File tree

40 files changed

+42
-36
lines changed

40 files changed

+42
-36
lines changed

cmd/auth/authtest/authtest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import (
1818
"bytes"
1919
"flag"
2020
"fmt"
21+
exec "golang.org/x/sys/execabs"
2122
"io"
2223
"log"
2324
"net/http"
2425
"net/textproto"
2526
"net/url"
2627
"os"
27-
"os/exec"
2828
"path/filepath"
2929
"strings"
3030
)

cmd/auth/gitauth/gitauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ package main
1616
import (
1717
"bytes"
1818
"fmt"
19+
exec "golang.org/x/sys/execabs"
1920
"log"
2021
"net/http"
2122
"net/url"
2223
"os"
23-
"os/exec"
2424
"path/filepath"
2525
"strings"
2626
)

cmd/compilebench/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ import (
8282
"encoding/json"
8383
"flag"
8484
"fmt"
85+
exec "golang.org/x/sys/execabs"
8586
"io/ioutil"
8687
"log"
8788
"os"
88-
"os/exec"
8989
"path/filepath"
9090
"regexp"
9191
"strconv"

cmd/cover/html.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88
"bufio"
99
"bytes"
1010
"fmt"
11+
exec "golang.org/x/sys/execabs"
1112
"html/template"
1213
"io"
1314
"io/ioutil"
1415
"math"
1516
"os"
16-
"os/exec"
1717
"path/filepath"
1818
"runtime"
1919

cmd/eg/eg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"go/format"
1515
"go/parser"
1616
"go/token"
17+
exec "golang.org/x/sys/execabs"
1718
"os"
18-
"os/exec"
1919
"strings"
2020

2121
"golang.org/x/tools/go/buildutil"

cmd/fiximports/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ import (
7979
"go/format"
8080
"go/parser"
8181
"go/token"
82+
exec "golang.org/x/sys/execabs"
8283
"io"
8384
"io/ioutil"
8485
"log"
8586
"os"
86-
"os/exec"
8787
"path"
8888
"path/filepath"
8989
"sort"

cmd/getgo/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"errors"
1414
"flag"
1515
"fmt"
16+
exec "golang.org/x/sys/execabs"
1617
"os"
17-
"os/exec"
1818
"strings"
1919
)
2020

cmd/getgo/system.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package main
99
import (
1010
"bytes"
1111
"context"
12-
"os/exec"
12+
exec "golang.org/x/sys/execabs"
1313
"runtime"
1414
"strings"
1515
)

cmd/go-contrib-init/contrib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
"flag"
1414
"fmt"
1515
"go/build"
16+
exec "golang.org/x/sys/execabs"
1617
"io/ioutil"
1718
"log"
1819
"os"
19-
"os/exec"
2020
"path/filepath"
2121
"regexp"
2222
"runtime"

cmd/godoc/goroot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
package main
66

77
import (
8+
exec "golang.org/x/sys/execabs"
89
"os"
9-
"os/exec"
1010
"path/filepath"
1111
"runtime"
1212
"strings"

cmd/godoc/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ import (
2525
"flag"
2626
"fmt"
2727
"go/build"
28+
exec "golang.org/x/sys/execabs"
2829
"io"
2930
"log"
3031
"net/http"
3132
_ "net/http/pprof" // to serve /debug/pprof/*
3233
"net/url"
3334
"os"
34-
"os/exec"
3535
"path"
3636
"path/filepath"
3737
"regexp"

cmd/goimports/goimports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"flag"
1212
"fmt"
1313
"go/scanner"
14+
exec "golang.org/x/sys/execabs"
1415
"io"
1516
"io/ioutil"
1617
"log"
1718
"os"
18-
"os/exec"
1919
"path/filepath"
2020
"runtime"
2121
"runtime/pprof"

cmd/stress/stress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ package main
1717
import (
1818
"flag"
1919
"fmt"
20+
exec "golang.org/x/sys/execabs"
2021
"io/ioutil"
2122
"os"
22-
"os/exec"
2323
"path/filepath"
2424
"regexp"
2525
"runtime"

cmd/toolstash/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ import (
127127
"bufio"
128128
"flag"
129129
"fmt"
130+
exec "golang.org/x/sys/execabs"
130131
"io"
131132
"io/ioutil"
132133
"log"
133134
"os"
134-
"os/exec"
135135
"path/filepath"
136136
"runtime"
137137
"strings"

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ require (
77
golang.org/x/mod v0.3.0
88
golang.org/x/net v0.0.0-20201021035429-f5854403a974
99
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
10+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4
1011
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
1112
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
1515
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
1616
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1717
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
18+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
19+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1820
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
1921
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
2022
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

go/internal/cgo/cgo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ import (
5757
"go/build"
5858
"go/parser"
5959
"go/token"
60+
exec "golang.org/x/sys/execabs"
6061
"io/ioutil"
6162
"log"
6263
"os"
63-
"os/exec"
6464
"path/filepath"
6565
"regexp"
6666
"strings"

go/internal/cgo/cgo_pkgconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"go/build"
11-
"os/exec"
11+
exec "golang.org/x/sys/execabs"
1212
"strings"
1313
)
1414

go/internal/gccgoimporter/gccgoinstallation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ package gccgoimporter
1010
import (
1111
"bufio"
1212
"go/types"
13+
exec "golang.org/x/sys/execabs"
1314
"os"
14-
"os/exec"
1515
"path/filepath"
1616
"strings"
1717
)

go/packages/external.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"bytes"
1313
"encoding/json"
1414
"fmt"
15+
exec "golang.org/x/sys/execabs"
1516
"os"
16-
"os/exec"
1717
"strings"
1818
)
1919

go/packages/golist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"encoding/json"
1111
"fmt"
1212
"go/types"
13+
exec "golang.org/x/sys/execabs"
1314
"io/ioutil"
1415
"log"
1516
"os"
16-
"os/exec"
1717
"path"
1818
"path/filepath"
1919
"reflect"

go/pointer/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"bytes"
99
"fmt"
1010
"go/types"
11+
exec "golang.org/x/sys/execabs"
1112
"log"
1213
"os"
13-
"os/exec"
1414
"runtime"
1515
"time"
1616

go/vcs/vcs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
"encoding/json"
2020
"errors"
2121
"fmt"
22+
exec "golang.org/x/sys/execabs"
2223
"log"
2324
"net/url"
2425
"os"
25-
"os/exec"
2626
"path/filepath"
2727
"regexp"
2828
"strconv"

gopls/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/sanity-io/litter v1.3.0
88
github.com/sergi/go-diff v1.1.0
99
golang.org/x/mod v0.4.0
10+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4
1011
golang.org/x/tools v0.0.0-20210104081019-d8d6ddbec6ee
1112
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
1213
honnef.co/go/tools v0.0.1-2020.1.6

gopls/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
4646
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4747
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4848
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
49+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
50+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4951
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
5052
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
5153
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

gopls/integration/replay/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"context"
1111
"flag"
1212
"fmt"
13+
exec "golang.org/x/sys/execabs"
1314
"log"
1415
"os"
15-
"os/exec"
1616
"sort"
1717
"strconv"
1818
"strings"

gopls/internal/hooks/licenses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,4 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
168168
169169
`
170170

171-
const licensesGeneratedFrom = "3fbcbd4a23419568c3f6609cc89f2918537c4ea023dc11a5bb55e3d3e5a67368"
171+
const licensesGeneratedFrom = "029a0f934a7bad22a7d47185055bc554b1ea23ce427351caa87d9a088fcfba4e"

gopls/internal/regtest/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"bytes"
99
"context"
1010
"fmt"
11+
exec "golang.org/x/sys/execabs"
1112
"io"
1213
"io/ioutil"
1314
"net"
1415
"os"
15-
"os/exec"
1616
"path/filepath"
1717
"runtime/pprof"
1818
"strings"

gopls/release/release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
"flag"
1616
"fmt"
1717
"go/types"
18+
exec "golang.org/x/sys/execabs"
1819
"io/ioutil"
1920
"log"
2021
"os"
21-
"os/exec"
2222
"os/user"
2323
"path/filepath"
2424
"strconv"

internal/gocommand/invoke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"bytes"
1010
"context"
1111
"fmt"
12+
exec "golang.org/x/sys/execabs"
1213
"io"
1314
"os"
14-
"os/exec"
1515
"regexp"
1616
"strconv"
1717
"strings"

internal/imports/mkstdlib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import (
1414
"bytes"
1515
"fmt"
1616
"go/format"
17+
exec "golang.org/x/sys/execabs"
1718
"io"
1819
"io/ioutil"
1920
"log"
2021
"os"
21-
"os/exec"
2222
"path/filepath"
2323
"regexp"
2424
"runtime"

internal/lsp/browser/browser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
package browser
77

88
import (
9+
exec "golang.org/x/sys/execabs"
910
"os"
10-
"os/exec"
1111
"runtime"
1212
"time"
1313
)

internal/lsp/cache/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"context"
1010
"encoding/json"
1111
"fmt"
12+
exec "golang.org/x/sys/execabs"
1213
"io"
1314
"io/ioutil"
1415
"os"
15-
"os/exec"
1616
"path"
1717
"path/filepath"
1818
"reflect"

internal/lsp/cmd/test/format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ package cmdtest
66

77
import (
88
"bytes"
9+
exec "golang.org/x/sys/execabs"
910
"io/ioutil"
1011
"os"
11-
"os/exec"
1212
"regexp"
1313
"strings"
1414
"testing"

internal/lsp/lsprpc/autostart_default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package lsprpc
66

77
import (
8-
"os/exec"
8+
exec "golang.org/x/sys/execabs"
99

1010
errors "golang.org/x/xerrors"
1111
)

internal/lsp/lsprpc/autostart_posix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"crypto/sha256"
1111
"errors"
1212
"fmt"
13+
exec "golang.org/x/sys/execabs"
1314
"log"
1415
"os"
15-
"os/exec"
1616
"os/user"
1717
"path/filepath"
1818
"strconv"

0 commit comments

Comments
 (0)