Merge PR #4510: Negative height paramter's value leads to undefined behavior
This commit is contained in:
parent
a32d5a46d7
commit
97d10210be
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue