mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #13959 from ptabor/20220419-log-injection
Fix code scanning alert: This log write receives unsanitized user input
This commit is contained in:
commit
52662ccd06
@ -90,12 +90,22 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
writeResponse(response{req.Val, req.Version, ""}, w)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("unknown op: %s\n", req.Op)
|
||||
fmt.Printf("unknown op: %s\n", escape(req.Op))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func escape(s string) string {
|
||||
escaped := strings.Replace(s, "\n", " ", -1)
|
||||
escaped = strings.Replace(escaped, "\r", " ", -1)
|
||||
return escaped
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", handler)
|
||||
http.ListenAndServe(":8080", nil)
|
||||
err := http.ListenAndServe(":8080", nil)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to listen and serve: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user