diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 3ae5537d..17bd7958 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -718,6 +718,7 @@ func (s *apiService) postSystemConfig(w http.ResponseWriter, r *http.Request) { defer s.systemConfigMut.Unlock() to, err := config.ReadJSON(r.Body, myID) + r.Body.Close() if err != nil { l.Warnln("decoding posted config:", err) http.Error(w, err.Error(), http.StatusBadRequest) @@ -940,10 +941,15 @@ func (s *apiService) getDBIgnores(w http.ResponseWriter, r *http.Request) { func (s *apiService) postDBIgnores(w http.ResponseWriter, r *http.Request) { qs := r.URL.Query() - var data map[string][]string - err := json.NewDecoder(r.Body).Decode(&data) + bs, err := ioutil.ReadAll(r.Body) r.Body.Close() + if err != nil { + http.Error(w, err.Error(), 500) + return + } + var data map[string][]string + err = json.Unmarshal(bs, &data) if err != nil { http.Error(w, err.Error(), 500) return diff --git a/lib/config/config.go b/lib/config/config.go index d981d83e..b179e921 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -11,6 +11,7 @@ import ( "encoding/json" "encoding/xml" "io" + "io/ioutil" "net/url" "os" "sort" @@ -92,7 +93,12 @@ func ReadJSON(r io.Reader, myID protocol.DeviceID) (Configuration, error) { util.SetDefaults(&cfg.Options) util.SetDefaults(&cfg.GUI) - err := json.NewDecoder(r).Decode(&cfg) + bs, err := ioutil.ReadAll(r) + if err != nil { + return cfg, err + } + + err = json.Unmarshal(bs, &cfg) cfg.OriginalVersion = cfg.Version cfg.prepare(myID) diff --git a/lib/discover/global.go b/lib/discover/global.go index 22a85b78..aa1dafe5 100644 --- a/lib/discover/global.go +++ b/lib/discover/global.go @@ -12,6 +12,7 @@ import ( "encoding/json" "errors" "io" + "io/ioutil" "net/http" "net/url" "strconv" @@ -154,9 +155,14 @@ func (c *globalClient) Lookup(device protocol.DeviceID) (addresses []string, err return nil, err } - var ann announcement - err = json.NewDecoder(resp.Body).Decode(&ann) + bs, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } resp.Body.Close() + + var ann announcement + err = json.Unmarshal(bs, &ann) return ann.Addresses, err }