diff --git a/CHANGELOG.md b/CHANGELOG.md index b00baba9408..d6b8bb3289a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/services/httpd/handler.go b/services/httpd/handler.go index 2a25f7e3ed5..0631e253589 100644 --- a/services/httpd/handler.go +++ b/services/httpd/handler.go @@ -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 diff --git a/services/httpd/handler_test.go b/services/httpd/handler_test.go index 930a2f0003b..ba9ec98da56 100644 --- a/services/httpd/handler_test.go +++ b/services/httpd/handler_test.go @@ -1,6 +1,7 @@ package httpd_test import ( + "bytes" "encoding/json" "errors" "fmt" @@ -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"`