aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcui fliter <imcusg@gmail.com>2023-11-03 15:03:12 +0800
committerCherry Mui <cherryyz@google.com>2024-05-01 03:56:37 +0000
commitc5698e31552953a0487ec23e0a015c02067065d3 (patch)
treef1bc43ed0da738a238bb28f6e472ffda7d9e78d1
parent959e65c41cf9aebb5af72466023ac66b01baf9e9 (diff)
downloadgo-c5698e31552953a0487ec23e0a015c02067065d3.tar.gz
go-c5698e31552953a0487ec23e0a015c02067065d3.zip
cmd/pprof: fix exception when file or path contains colon
Fixes #63924 Change-Id: I4ea17979faaca04eb6b046abffca2dd77397e0cb Reviewed-on: https://go-review.googlesource.com/c/go/+/539595 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
-rw-r--r--src/cmd/pprof/pprof.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/cmd/pprof/pprof.go b/src/cmd/pprof/pprof.go
index d4db9df285..24d6ee04a0 100644
--- a/src/cmd/pprof/pprof.go
+++ b/src/cmd/pprof/pprof.go
@@ -45,6 +45,16 @@ type fetcher struct {
}
func (f *fetcher) Fetch(src string, duration, timeout time.Duration) (*profile.Profile, string, error) {
+ // Firstly, determine if the src is an existing file on the disk.
+ // If it is a file, let regular pprof open it.
+ // If it is not a file, when the src contains `:`
+ // (e.g. mem_2023-11-02_03:55:24 or abc:123/mem_2023-11-02_03:55:24),
+ // url.Parse will recognize it as a link and ultimately report an error,
+ // similar to `abc:123/mem_2023-11-02_03:55:24:
+ // Get "http://abc:123/mem_2023-11-02_03:55:24": dial tcp: lookup abc: no such host`
+ if _, openErr := os.Stat(src); openErr == nil {
+ return nil, "", nil
+ }
sourceURL, timeout := adjustURL(src, duration, timeout)
if sourceURL == "" {
// Could not recognize URL, let regular pprof attempt to fetch the profile (eg. from a file)