From 3c024faabb25894a622fb343bcef5a57506205f1 Mon Sep 17 00:00:00 2001 From: yuli Date: Tue, 28 Apr 2020 15:50:41 +0000 Subject: [PATCH] validate body size --- src/utils.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils.go b/src/utils.go index 30f84d7..ed1114b 100644 --- a/src/utils.go +++ b/src/utils.go @@ -371,6 +371,9 @@ func getJSONPostData(r *http.Request) (map[string]interface{}, error) { if err != nil { return nil, err } + if len(body) < 3 { + return nil, nil + } if strings.HasPrefix(cType, "application/x-www-form-urlencoded") { if body[0] == '{' { return nil, errors.New("wrong content-type, json instead of url encoded data") @@ -388,9 +391,6 @@ func getJSONPostData(r *http.Request) (map[string]interface{}, error) { records[key] = value[0] } } else if strings.HasPrefix(cType, "application/json") { - if len(body) < 3 { - return nil, nil - } err = json.Unmarshal(body, &records) if err != nil { return nil, err