Skip to content

Commit

Permalink
fix(tasks): add content length check to decode force run request
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirieGray committed Jan 8, 2020
1 parent 128b9ee commit 6d037e8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions http/task_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,23 @@ func decodeForceRunRequest(ctx context.Context, r *http.Request) (forceRunReques
var req struct {
ScheduledFor string `json:"scheduledFor"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return forceRunRequest{}, err

if r.ContentLength != 0 && r.ContentLength < 1000 { // prevent attempts to use up memory since r.Body should include at most one item (RunManually)
fmt.Println("inside the if (length is not 0 ) ")
buf := new(bytes.Buffer)
_, err := buf.ReadFrom(r.Body)
if err != nil {
return forceRunRequest{}, &influxdb.Error{
Code: influxdb.EInvalid,
Err: err,
}
}
defer r.Body.Close()

err = json.Unmarshal(buf.Bytes(), &req)
if err != nil {
return forceRunRequest{}, err
}
}

var t time.Time
Expand Down

0 comments on commit 6d037e8

Please sign in to comment.