From 61415bee33fa1d798499691290df4eaf9e438c03 Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Wed, 6 Nov 2024 17:51:21 +0000 Subject: [PATCH] gopls/internal/cache: guard against malformed paths in port.matches 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 Auto-Submit: Robert Findley LUCI-TryBot-Result: Go LUCI --- gopls/internal/cache/port.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gopls/internal/cache/port.go b/gopls/internal/cache/port.go index e62ebe29903..40005bcf6d4 100644 --- a/gopls/internal/cache/port.go +++ b/gopls/internal/cache/port.go @@ -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.