Fix links retrieval handler allowing negative limit and offset values

This commit is contained in:
Andrey Chervyakov 2021-03-18 23:17:18 +06:00
parent 458ae28901
commit 2baa74d520

View file

@ -53,7 +53,7 @@ func allRetrievalHandler(ctx echo.Context, serv Service) error {
limit := 20 limit := 20
if v := ctx.QueryParam("limit"); v != "" { if v := ctx.QueryParam("limit"); v != "" {
num, err := strconv.Atoi(v) num, err := strconv.Atoi(v)
if err != nil { if err != nil || num < 0 {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid limit value.") return echo.NewHTTPError(http.StatusBadRequest, "Invalid limit value.")
} }
@ -63,7 +63,7 @@ func allRetrievalHandler(ctx echo.Context, serv Service) error {
offset := 0 offset := 0
if v := ctx.QueryParam("offset"); v != "" { if v := ctx.QueryParam("offset"); v != "" {
num, err := strconv.Atoi(v) num, err := strconv.Atoi(v)
if err != nil { if err != nil || num < 0 {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid offset value.") return echo.NewHTTPError(http.StatusBadRequest, "Invalid offset value.")
} }