Merge PR #4510: Negative height paramter's value leads to undefined behavior

This commit is contained in:
Alessio Treglia 2019-06-07 19:11:50 +01:00 committed by Alexander Bezobchuk
parent a32d5a46d7
commit 97d10210be
2 changed files with 6 additions and 1 deletions

View File

@ -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)
}

View File

@ -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) {