Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go work use -r panics when given a directory that does not exist #51841

Closed
notfilippo opened this issue Mar 21, 2022 · 6 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@notfilippo
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.18 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/rossi/Library/Caches/go-build"
GOENV="/Users/rossi/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/rossi/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/rossi/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.18/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.18/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK="/Users/rossi/go.work"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/p0/53xvt8l57dj14b_pxf9dyyvw0000gn/T/go-build2599584196=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go work use -r does_not_exist

What did you expect to see?

An error message detailing that the directory does not exist.

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x141cdf5]

goroutine 1 [running]:
cmd/go/internal/workcmd.runUse.func2({0x7ff7bfeff8ff, 0xe}, {0x0, 0x0}, {0x5?, 0xc0000d3880?})
	/usr/local/Cellar/go/1.18/libexec/src/cmd/go/internal/workcmd/use.go:118 +0x35
cmd/go/internal/fsys.Walk({0x7ff7bfeff8ff, 0xe}, 0xc0000d39a8)
	/usr/local/Cellar/go/1.18/libexec/src/cmd/go/internal/fsys/fsys.go:441 +0x64
cmd/go/internal/workcmd.runUse({0x16dbd58?, 0xc00002a110?}, 0xc00002c528?, {0xc0000200e0, 0x1, 0x2?})
	/usr/local/Cellar/go/1.18/libexec/src/cmd/go/internal/workcmd/use.go:117 +0x97f
main.invoke(0x19be780, {0xc0000200c0, 0x3, 0x3})
	/usr/local/Cellar/go/1.18/libexec/src/cmd/go/main.go:218 +0x2ee
main.main()
	/usr/local/Cellar/go/1.18/libexec/src/cmd/go/main.go:175 +0x78e

Proposed solution

In go/src/cmd/go/internal/workcmd/use.go, starting from line 110.

+absArg, _ := pathRel(workDir, useDir)

+info, err := os.Stat(absArg)
+if err != nil {
+	if os.IsNotExist(err) {
+		base.Errorf("go: %v directory not found", absArg)
+	} else {
+		base.Errorf("go: %v", err)
+	}
+	continue
+} else if !info.IsDir() {
+	base.Errorf("go: %s not a directory", absArg)
+	continue
+}

if !*useR {
	  lookDir(useDir)
	  continue
}

// Add or remove entries for any subdirectories that still exist.

err = fsys.Walk(useDir, func(path string, info fs.FileInfo, err error) error {
+	if err != nil {
+		return err
+	}
	...
}

Happy to open a pull request if needed

@mvdan
Copy link
Member

mvdan commented Mar 21, 2022

@notfilippo please just send a patch, just like #51749 (comment). Also note that issue, which is very similar, as the two patches might conflict.

@notfilippo notfilippo changed the title cmd/go: go work -r panics when given a directory that does not exist cmd/go: go work use -r panics when given a directory that does not exist Mar 21, 2022
notfilippo added a commit to notfilippo/go that referenced this issue Mar 21, 2022
Check if paths passed as arguments are existing directories.

Fixes golang#51841 golang#51749
@gopherbot
Copy link

Change https://go.dev/cl/394154 mentions this issue: cmd/go: prevent panic in go work use

notfilippo added a commit to notfilippo/go that referenced this issue Mar 21, 2022
Check if paths passed as arguments are existing directories.

Fixes golang#51841 golang#51749
@mknyszek mknyszek added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 21, 2022
@mknyszek mknyszek added this to the Go1.19 milestone Mar 21, 2022
@mknyszek
Copy link
Contributor

CC @matloob @bcmills

notfilippo added a commit to notfilippo/go that referenced this issue Mar 31, 2022
Check if paths passed as arguments are existing directories.

Fixes golang#51841 golang#51749
notfilippo added a commit to notfilippo/go that referenced this issue Apr 4, 2022
Check if paths passed as arguments are existing directories.

Fixes golang#51841
Fixes golang#51749
@bcmills
Copy link
Contributor

bcmills commented Apr 4, 2022

@gopherbot, please backport to Go 1.18. This is a user-facing panic in a feature introduced in Go 1.18.

@gopherbot
Copy link

Backport issue(s) opened: #52140 (for 1.18).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link

Change https://go.dev/cl/397995 mentions this issue: [release-branch.go1.18] cmd/go: prevent panic in go work use

gopherbot pushed a commit that referenced this issue Apr 5, 2022
Check if paths passed as arguments are existing directories.

Fixes #52140
Updates #51841

Change-Id: Icfd148627e6f2c4651d6f923a37d413e68c67f6c
GitHub-Last-Rev: 77fffa7
GitHub-Pull-Request: #51845
Reviewed-on: https://go-review.googlesource.com/c/go/+/394154
Trust: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/397995
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
@golang golang locked and limited conversation to collaborators Apr 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants