Skip to content

net/http/pprof: avoid panic with user-defined "GET /" route #65791

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/net/http/pprof/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// The package is typically only imported for the side effect of
// registering its HTTP handlers.
// The handled paths all begin with /debug/pprof/.
// As of Go 1.22, all the paths must be requested with GET.
//
// To use pprof, link this package into your program:
//
Expand Down Expand Up @@ -75,6 +76,7 @@ import (
"context"
"fmt"
"html"
"internal/godebug"
"internal/profile"
"io"
"log"
Expand All @@ -91,11 +93,15 @@ import (
)

func init() {
http.HandleFunc("/debug/pprof/", Index)
http.HandleFunc("/debug/pprof/cmdline", Cmdline)
http.HandleFunc("/debug/pprof/profile", Profile)
http.HandleFunc("/debug/pprof/symbol", Symbol)
http.HandleFunc("/debug/pprof/trace", Trace)
prefix := ""
if godebug.New("httpmuxgo121").Value() != "1" {
prefix = "GET "
}
http.HandleFunc(prefix+"/debug/pprof/", Index)
http.HandleFunc(prefix+"/debug/pprof/cmdline", Cmdline)
http.HandleFunc(prefix+"/debug/pprof/profile", Profile)
http.HandleFunc(prefix+"/debug/pprof/symbol", Symbol)
http.HandleFunc(prefix+"/debug/pprof/trace", Trace)
}

// Cmdline responds with the running program's
Expand Down