fix(master):fix the problem of gosec

Signed-off-by: shuqiang-zheng <zhengshuqiang@oppo.com>
This commit is contained in:
shuqiang-zheng 2023-12-04 16:17:01 +08:00 committed by Whale Tang
parent 40ddb416d0
commit bd13838523
4 changed files with 44 additions and 8 deletions

View File

@ -243,15 +243,24 @@ func main() {
if profPort != "" {
go func() {
mainMux := http.NewServeMux()
mux := http.NewServeMux()
mux.HandleFunc(log.SetLogLevelPath, log.SetLogLevel)
http.HandleFunc(log.SetLogLevelPath, log.SetLogLevel)
mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index))
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
mux.Handle("/debug/", http.HandlerFunc(pprof.Index))
e := http.ListenAndServe(fmt.Sprintf(":%v", profPort), mux)
mainHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if strings.HasPrefix(req.URL.Path, "/debug/") {
mux.ServeHTTP(w, req)
} else {
http.DefaultServeMux.ServeHTTP(w, req)
}
})
mainMux.Handle("/", mainHandler)
e := http.ListenAndServe(fmt.Sprintf(":%v", profPort), mainMux)
if e != nil {
log.LogFlush()
err = errors.NewErrorf("cannot listen pprof %v err %v", profPort, err)

View File

@ -610,7 +610,7 @@ func mount(opt *proto.MountOptions) (fsConn *fuse.Conn, super *cfs.Super, err er
if opt.LocallyProf {
pprofAddr = "127.0.0.1:" + opt.Profport
}
mainMux := http.NewServeMux()
mux := http.NewServeMux()
mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index))
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
@ -618,8 +618,16 @@ func mount(opt *proto.MountOptions) (fsConn *fuse.Conn, super *cfs.Super, err er
mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
mux.Handle("/debug/", http.HandlerFunc(pprof.Index))
mainHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if strings.HasPrefix(req.URL.Path, "/debug/") {
mux.ServeHTTP(w, req)
} else {
http.DefaultServeMux.ServeHTTP(w, req)
}
})
mainMux.Handle("/", mainHandler)
go waitListenAndServe(statusCh, pprofAddr, mux)
go waitListenAndServe(statusCh, pprofAddr, mainMux)
if err = <-statusCh; err != nil {
daemonize.SignalOutcome(err)
return

View File

@ -288,15 +288,24 @@ func main() {
if profPort != "" {
go func() {
mainMux := http.NewServeMux()
mux := http.NewServeMux()
mux.HandleFunc(log.SetLogLevelPath, log.SetLogLevel)
http.HandleFunc(log.SetLogLevelPath, log.SetLogLevel)
mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index))
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
mux.Handle("/debug/", http.HandlerFunc(pprof.Index))
e := http.ListenAndServe(fmt.Sprintf(":%v", profPort), mux)
mainHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if strings.HasPrefix(req.URL.Path, "/debug/") {
mux.ServeHTTP(w, req)
} else {
http.DefaultServeMux.ServeHTTP(w, req)
}
})
mainMux.Handle("/", mainHandler)
e := http.ListenAndServe(fmt.Sprintf(":%v", profPort), mainMux)
if e != nil {
log.LogFlush()
err = errors.NewErrorf("cannot listen pprof %v err %v", profPort, e)

View File

@ -22,6 +22,7 @@ import (
"net/http/pprof"
"path"
gopath "path"
"strings"
"sync"
"sync/atomic"
"time"
@ -94,15 +95,24 @@ func NewClient(config PreloadConfig) *PreLoadClient {
if config.ProfPort != "" {
go func() {
mainMux := http.NewServeMux()
mux := http.NewServeMux()
mux.HandleFunc(log.SetLogLevelPath, log.SetLogLevel)
http.HandleFunc(log.SetLogLevelPath, log.SetLogLevel)
mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index))
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
mux.Handle("/debug/", http.HandlerFunc(pprof.Index))
e := http.ListenAndServe(fmt.Sprintf(":%v", config.ProfPort), mux)
mainHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if strings.HasPrefix(req.URL.Path, "/debug/") {
mux.ServeHTTP(w, req)
} else {
http.DefaultServeMux.ServeHTTP(w, req)
}
})
mainMux.Handle("/", mainHandler)
e := http.ListenAndServe(fmt.Sprintf(":%v", config.ProfPort), mainMux)
if e != nil {
log.LogWarnf("newClient newEBSClient cannot listen pprof (%v)", config.ProfPort)
}