Bugfix: Avoid divide-by-zero panic on query_range?step=0

This commit is contained in:
Anders Daljord Morken 2016-08-16 15:10:02 +02:00
parent 6bfd30269a
commit e9885ecb94
2 changed files with 16 additions and 0 deletions

View File

@ -187,6 +187,11 @@ func (api *API) queryRange(r *http.Request) (interface{}, *apiError) {
return nil, &apiError{errorBadData, err}
}
if step <= 0 {
err := errors.New("zero or negative query resolution step widths are not accepted. Try a positive integer")
return nil, &apiError{errorBadData, err}
}
// For safety, limit the number of returned points per timeseries.
// This is sufficient for 60s resolution for a week or 1h resolution for a year.
if end.Sub(start)/step > 11000 {

View File

@ -187,6 +187,17 @@ func TestEndpoints(t *testing.T) {
},
errType: errorBadData,
},
// Invalid step
{
endpoint: api.queryRange,
query: url.Values{
"query": []string{"time()"},
"start": []string{"1"},
"end": []string{"2"},
"step": []string{"0"},
},
errType: errorBadData,
},
{
endpoint: api.labelValues,
params: map[string]string{