Skip to content

Commit

Permalink
net/http: respond with 400 Bad Request for empty hex number of chunk …
Browse files Browse the repository at this point in the history
…length

Fixes #64517

Change-Id: I78b8a6a83301deee05c3ff052a6adcd1f965aef2
Reviewed-on: https://go-review.googlesource.com/c/go/+/553835
Auto-Submit: Damien Neil <dneil@google.com>
Commit-Queue: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
  • Loading branch information
panjf2000 authored and gopherbot committed Jan 4, 2024
1 parent 1e07c14 commit ead47b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/net/http/internal/chunked.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ type FlushAfterChunkWriter struct {
}

func parseHexUint(v []byte) (n uint64, err error) {
if len(v) == 0 {
return 0, errors.New("empty hex number for chunk length")
}
for i, b := range v {
switch {
case '0' <= b && b <= '9':
Expand Down
1 change: 1 addition & 0 deletions src/net/http/internal/chunked_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func TestParseHexUint(t *testing.T) {
{"00000000000000000", 0, "http chunk length too large"}, // could accept if we wanted
{"10000000000000000", 0, "http chunk length too large"},
{"00000000000000001", 0, "http chunk length too large"}, // could accept if we wanted
{"", 0, "empty hex number for chunk length"},
}
for i := uint64(0); i <= 1234; i++ {
tests = append(tests, testCase{in: fmt.Sprintf("%x", i), want: i})
Expand Down

0 comments on commit ead47b0

Please sign in to comment.