From eca0d44cec58951fb716e540dcc21c0f527686d5 Mon Sep 17 00:00:00 2001 From: hopehook Date: Wed, 9 Feb 2022 20:20:06 +0800 Subject: [PATCH] net/http: fix nil body causing ParseMultipartForm to panic ParseMultipartForm relies on a valid multipartReader, if the request body is nil, the multipartReader should return an error. This way ParseMultipartForm can return an error instead of causing mr.ReadForm(maxMemory) to panic Fixes #48206 Change-Id: Ief906f2340c7ab29cacbd5f56892117202a0b911 Reviewed-on: https://go-review.googlesource.com/c/go/+/384454 Trust: Damien Neil Run-TryBot: Damien Neil TryBot-Result: Gopher Robot Reviewed-by: Damien Neil Reviewed-by: Brad Fitzpatrick Trust: Brad Fitzpatrick --- src/net/http/request.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/net/http/request.go b/src/net/http/request.go index f8f1eeab29d..dbe947aec44 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -480,6 +480,9 @@ func (r *Request) multipartReader(allowMixed bool) (*multipart.Reader, error) { if v == "" { return nil, ErrNotMultipart } + if r.Body == nil { + return nil, errors.New("missing form body") + } d, params, err := mime.ParseMediaType(v) if err != nil || !(d == "multipart/form-data" || allowMixed && d == "multipart/mixed") { return nil, ErrNotMultipart