Skip to content

Commit

Permalink
Fix bad request trailer panic
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Dec 13, 2021
1 parent 4aadf9a commit 7db0597
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion header.go
Original file line number Diff line number Diff line change
Expand Up @@ -2736,7 +2736,11 @@ func (h *RequestHeader) parseHeaders(buf []byte) (int, error) {
continue
}
if caseInsensitiveCompare(s.key, strTrailer) {
err = h.SetTrailerBytes(s.value)
if nerr := h.SetTrailerBytes(s.value); nerr != nil {
if err == nil {
err = nerr
}
}
continue
}
}
Expand Down
6 changes: 6 additions & 0 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fasthttp
import (
"bufio"
"bytes"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
Expand All @@ -24,6 +25,11 @@ func TestInvalidTrailers(t *testing.T) {
if err == io.EOF {
t.Fatal(err)
}

b, _ := base64.StdEncoding.DecodeString("tCAKIDoKCToKICAKCToKICAKCToKIAogOgoJOgogIAoJOgovIC8vOi4KOh0KVFJhSUxlUjo9HT09HQpUUmFJTGVSOicQAApUUmFJTGVSOj0gHSAKCT09HQoKOgoKCgo=")
if err := (&Request{}).Read(bufio.NewReader(bytes.NewReader(b))); !strings.Contains(err.Error(), "error when reading request headers: invalid header key") {
t.Fatalf("%#v", err)
}
}

func TestResponseEmptyTransferEncoding(t *testing.T) {
Expand Down

0 comments on commit 7db0597

Please sign in to comment.