Skip to content

Commit

Permalink
Merge PR #4510: Negative height paramter's value leads to undefined b…
Browse files Browse the repository at this point in the history
…ehavior
  • Loading branch information
alessio authored and alexanderbez committed Jun 7, 2019
1 parent a32d5a4 commit 97d1021
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions types/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ func ParseQueryHeightOrReturnBadRequest(w http.ResponseWriter, cliCtx context.CL
return cliCtx, false
}

if height < 0 {
WriteErrorResponse(w, http.StatusBadRequest, "height must be equal or greater than zero")
return cliCtx, false
}

if height > 0 {
cliCtx = cliCtx.WithHeight(height)
}
Expand Down
2 changes: 1 addition & 1 deletion types/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestParseQueryHeight(t *testing.T) {
{"no height", req0, httptest.NewRecorder(), context.CLIContext{}, emptyHeight, true},
{"height", req1, httptest.NewRecorder(), context.CLIContext{}, height, true},
{"invalid height", req2, httptest.NewRecorder(), context.CLIContext{}, emptyHeight, false},
{"negative height", req3, httptest.NewRecorder(), context.CLIContext{}, emptyHeight, true},
{"negative height", req3, httptest.NewRecorder(), context.CLIContext{}, emptyHeight, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 97d1021

Please sign in to comment.