Skip to content

Commit

Permalink
gopls/internal/cache: guard against malformed paths in port.matches
Browse files Browse the repository at this point in the history
It's possible that we may encounter the path inconsistency of
golang/go#67288 due to unclean or relative paths. Guard against this
with a new bug report.

For golang/go#67288

Change-Id: I37ac1f74334bcb9e955d75e436f74398c73f0acb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626015
Reviewed-by: Alan Donovan <[email protected]>
Auto-Submit: Robert Findley <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
findleyr authored and gopherbot committed Nov 7, 2024
1 parent 9a89d3a commit 61415be
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gopls/internal/cache/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ var (
func (p port) matches(path string, content []byte) bool {
ctxt := build.Default // make a copy
ctxt.UseAllFiles = false
path = filepath.Clean(path)
if !filepath.IsAbs(path) {
bug.Reportf("non-abs file path %q", path)
return false // fail closed
}
dir, name := filepath.Split(path)

// The only virtualized operation called by MatchFile is OpenFile.
Expand Down

0 comments on commit 61415be

Please sign in to comment.