Use httputil.UnmarshalJSON as that should enforce UTF-8 correctness

This commit is contained in:
Neil Alexander 2022-03-28 10:09:14 +01:00
parent c5413b9f4d
commit e42bab8c1d
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -41,6 +41,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/auth" "github.com/matrix-org/dendrite/clientapi/auth"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/clientapi/httputil"
"github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/clientapi/userutil" "github.com/matrix-org/dendrite/clientapi/userutil"
userapi "github.com/matrix-org/dendrite/userapi/api" userapi "github.com/matrix-org/dendrite/userapi/api"
@ -549,7 +550,7 @@ func Register(
r.InitialDisplayName = data.InitialDisplayName r.InitialDisplayName = data.InitialDisplayName
r.InhibitLogin = data.InhibitLogin r.InhibitLogin = data.InhibitLogin
} }
if resErr := json.Unmarshal(reqBody, &r); resErr != nil { if resErr := httputil.UnmarshalJSON(reqBody, &r); resErr != nil {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("Request body contains invalid JSON"), JSON: jsonerror.BadJSON("Request body contains invalid JSON"),