os/exec: LookPath on Unix shouldn't look in cwd when PATH is empty

R=golang-dev, dave, bradfitz
CC=golang-dev
https://golang.org/cl/7305053
This commit is contained in:
Péter Surányi 2013-02-07 06:41:35 -08:00 committed by Brad Fitzpatrick
parent 80e1cf73eb
commit fe7dbea00e
2 changed files with 55 additions and 0 deletions

View file

@ -42,6 +42,9 @@ func LookPath(file string) (string, error) {
return "", &Error{file, err}
}
pathenv := os.Getenv("PATH")
if pathenv == "" {
return "", &Error{file, ErrNotFound}
}
for _, dir := range strings.Split(pathenv, ":") {
if dir == "" {
// Unix shell semantics: path element "" means "."