Skip to content

Commit

Permalink
Merge pull request #4625 from influxdb/panic_points
Browse files Browse the repository at this point in the history
Correctly handle bad write requests
  • Loading branch information
otoolep committed Oct 30, 2015
2 parents cbe56e0 + bd0c304 commit d909b0c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
- [#4587](https://github.com/influxdb/influxdb/pull/4587): Prevent NaN float values from being stored
- [#4596](https://github.com/influxdb/influxdb/pull/4596): Skip empty string for start position when parsing line protocol @Thanks @ch33hau
- [#4610](https://github.com/influxdb/influxdb/pull/4610): Make internal stats names consistent with Go style.
- [#4625](https://github.com/influxdb/influxdb/pull/4625): Correctly handle bad write requests. Thanks @oiooj.

## v0.9.4 [2015-09-14]

Expand Down
2 changes: 1 addition & 1 deletion services/httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func (h *Handler) serveWriteLine(w http.ResponseWriter, r *http.Request, body []
}

// check that the byte is in the standard ascii code range
if body[i] > 32 {
if body[i] > 32 || i >= len(body)-1 {
break
}
i += 1
Expand Down
12 changes: 12 additions & 0 deletions services/httpd/handler_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package httpd_test

import (
"bytes"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -343,6 +344,17 @@ func TestHandler_PingWaitForLeaderBadRequest(t *testing.T) {
}
}

// Ensure write endpoint can handle bad requests
func TestHandler_HandleBadRequestBody(t *testing.T) {
b := bytes.NewReader(make([]byte, 10))
h := NewHandler(false)
w := httptest.NewRecorder()
h.ServeHTTP(w, MustNewRequest("POST", "/write", b))
if w.Code != http.StatusBadRequest {
t.Fatalf("unexpected status: %d", w.Code)
}
}

func TestMarshalJSON_NoPretty(t *testing.T) {
if b := httpd.MarshalJSON(struct {
Name string `json:"name"`
Expand Down

0 comments on commit d909b0c

Please sign in to comment.