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 <katiehockman@google.com>
Reviewed-by: Russ Cox <rsc@google.com>
Reviewed-on: https://go-review.googlesource.com/c/tools/+/284773
Run-TryBot: Roland Shoemaker <roland@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Roland Shoemaker <roland@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Roland Shoemaker 2021-01-11 10:19:11 -08:00
parent a46736d9d9
commit fe37c9e135
40 changed files with 42 additions and 36 deletions

View File

@ -18,13 +18,13 @@ import (
"bytes"
"flag"
"fmt"
exec "golang.org/x/sys/execabs"
"io"
"log"
"net/http"
"net/textproto"
"net/url"
"os"
"os/exec"
"path/filepath"
"strings"
)

View File

@ -16,11 +16,11 @@ package main
import (
"bytes"
"fmt"
exec "golang.org/x/sys/execabs"
"log"
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
"strings"
)

View File

@ -82,10 +82,10 @@ import (
"encoding/json"
"flag"
"fmt"
exec "golang.org/x/sys/execabs"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"

View File

@ -8,12 +8,12 @@ import (
"bufio"
"bytes"
"fmt"
exec "golang.org/x/sys/execabs"
"html/template"
"io"
"io/ioutil"
"math"
"os"
"os/exec"
"path/filepath"
"runtime"

View File

@ -14,8 +14,8 @@ import (
"go/format"
"go/parser"
"go/token"
exec "golang.org/x/sys/execabs"
"os"
"os/exec"
"strings"
"golang.org/x/tools/go/buildutil"

View File

@ -79,11 +79,11 @@ import (
"go/format"
"go/parser"
"go/token"
exec "golang.org/x/sys/execabs"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"path/filepath"
"sort"

View File

@ -13,8 +13,8 @@ import (
"errors"
"flag"
"fmt"
exec "golang.org/x/sys/execabs"
"os"
"os/exec"
"strings"
)

View File

@ -9,7 +9,7 @@ package main
import (
"bytes"
"context"
"os/exec"
exec "golang.org/x/sys/execabs"
"runtime"
"strings"
)

View File

@ -13,10 +13,10 @@ import (
"flag"
"fmt"
"go/build"
exec "golang.org/x/sys/execabs"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"

View File

@ -5,8 +5,8 @@
package main
import (
exec "golang.org/x/sys/execabs"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

View File

@ -25,13 +25,13 @@ import (
"flag"
"fmt"
"go/build"
exec "golang.org/x/sys/execabs"
"io"
"log"
"net/http"
_ "net/http/pprof" // to serve /debug/pprof/*
"net/url"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"

View File

@ -11,11 +11,11 @@ import (
"flag"
"fmt"
"go/scanner"
exec "golang.org/x/sys/execabs"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"runtime/pprof"

View File

@ -17,9 +17,9 @@ package main
import (
"flag"
"fmt"
exec "golang.org/x/sys/execabs"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"

View File

@ -127,11 +127,11 @@ import (
"bufio"
"flag"
"fmt"
exec "golang.org/x/sys/execabs"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

1
go.mod
View File

@ -7,5 +7,6 @@ require (
golang.org/x/mod v0.3.0
golang.org/x/net v0.0.0-20201021035429-f5854403a974
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
)

2
go.sum
View File

@ -15,6 +15,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

View File

@ -57,10 +57,10 @@ import (
"go/build"
"go/parser"
"go/token"
exec "golang.org/x/sys/execabs"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

View File

@ -8,7 +8,7 @@ import (
"errors"
"fmt"
"go/build"
"os/exec"
exec "golang.org/x/sys/execabs"
"strings"
)

View File

@ -10,8 +10,8 @@ package gccgoimporter
import (
"bufio"
"go/types"
exec "golang.org/x/sys/execabs"
"os"
"os/exec"
"path/filepath"
"strings"
)

View File

@ -12,8 +12,8 @@ import (
"bytes"
"encoding/json"
"fmt"
exec "golang.org/x/sys/execabs"
"os"
"os/exec"
"strings"
)

View File

@ -10,10 +10,10 @@ import (
"encoding/json"
"fmt"
"go/types"
exec "golang.org/x/sys/execabs"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"path/filepath"
"reflect"

View File

@ -8,9 +8,9 @@ import (
"bytes"
"fmt"
"go/types"
exec "golang.org/x/sys/execabs"
"log"
"os"
"os/exec"
"runtime"
"time"

View File

@ -19,10 +19,10 @@ import (
"encoding/json"
"errors"
"fmt"
exec "golang.org/x/sys/execabs"
"log"
"net/url"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"

View File

@ -7,6 +7,7 @@ require (
github.com/sanity-io/litter v1.3.0
github.com/sergi/go-diff v1.1.0
golang.org/x/mod v0.4.0
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4
golang.org/x/tools v0.0.0-20210104081019-d8d6ddbec6ee
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
honnef.co/go/tools v0.0.1-2020.1.6

View File

@ -46,6 +46,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

View File

@ -10,9 +10,9 @@ import (
"context"
"flag"
"fmt"
exec "golang.org/x/sys/execabs"
"log"
"os"
"os/exec"
"sort"
"strconv"
"strings"

View File

@ -168,4 +168,4 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
`
const licensesGeneratedFrom = "3fbcbd4a23419568c3f6609cc89f2918537c4ea023dc11a5bb55e3d3e5a67368"
const licensesGeneratedFrom = "029a0f934a7bad22a7d47185055bc554b1ea23ce427351caa87d9a088fcfba4e"

View File

@ -8,11 +8,11 @@ import (
"bytes"
"context"
"fmt"
exec "golang.org/x/sys/execabs"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
"path/filepath"
"runtime/pprof"
"strings"

View File

@ -15,10 +15,10 @@ import (
"flag"
"fmt"
"go/types"
exec "golang.org/x/sys/execabs"
"io/ioutil"
"log"
"os"
"os/exec"
"os/user"
"path/filepath"
"strconv"

View File

@ -9,9 +9,9 @@ import (
"bytes"
"context"
"fmt"
exec "golang.org/x/sys/execabs"
"io"
"os"
"os/exec"
"regexp"
"strconv"
"strings"

View File

@ -14,11 +14,11 @@ import (
"bytes"
"fmt"
"go/format"
exec "golang.org/x/sys/execabs"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"

View File

@ -6,8 +6,8 @@
package browser
import (
exec "golang.org/x/sys/execabs"
"os"
"os/exec"
"runtime"
"time"
)

View File

@ -9,10 +9,10 @@ import (
"context"
"encoding/json"
"fmt"
exec "golang.org/x/sys/execabs"
"io"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"reflect"

View File

@ -6,9 +6,9 @@ package cmdtest
import (
"bytes"
exec "golang.org/x/sys/execabs"
"io/ioutil"
"os"
"os/exec"
"regexp"
"strings"
"testing"

View File

@ -5,7 +5,7 @@
package lsprpc
import (
"os/exec"
exec "golang.org/x/sys/execabs"
errors "golang.org/x/xerrors"
)

View File

@ -10,9 +10,9 @@ import (
"crypto/sha256"
"errors"
"fmt"
exec "golang.org/x/sys/execabs"
"log"
"os"
"os/exec"
"os/user"
"path/filepath"
"strconv"

View File

@ -10,9 +10,9 @@ import (
"bytes"
"fmt"
"go/build"
exec "golang.org/x/sys/execabs"
"io/ioutil"
"os"
"os/exec"
"runtime"
"strings"
"sync"

View File

@ -19,6 +19,7 @@ import (
"errors"
"go/parser"
"go/token"
exec "golang.org/x/sys/execabs"
"io"
"io/ioutil"
"log"
@ -26,7 +27,6 @@ import (
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

View File

@ -18,9 +18,9 @@ import (
"go/build"
"go/format"
"go/token"
exec "golang.org/x/sys/execabs"
"log"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"

View File

@ -17,11 +17,11 @@ import (
"go/parser"
"go/token"
"go/types"
exec "golang.org/x/sys/execabs"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"regexp"
"sort"