]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: fix nil body causing ParseMultipartForm to panic
authorhopehook <hopehook.com@gmail.com>
Wed, 9 Feb 2022 12:20:06 +0000 (20:20 +0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 22 Mar 2022 15:16:23 +0000 (15:16 +0000)
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 <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Trust: Brad Fitzpatrick <bradfitz@golang.org>

src/net/http/request.go

index f8f1eeab29d4bb673465530a70e576ca8c66f8ea..dbe947aec44b4572b73fa0e5d991324fdcecee1c 100644 (file)
@@ -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