From 9b04e17893dbf91326c0f68ce7627d7bb07cf515 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Tue, 14 Sep 2021 22:23:01 +0200 Subject: api: handle nil pointer dereference in rest endpoints When `?all=garbage` is passed to an API endpoint schema validation fails and err is nil. Wrapf uses err to create an error message causing a nil pointer dereference. Signed-off-by: Jelle van der Waa --- pkg/api/handlers/compat/containers.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'pkg/api/handlers/compat/containers.go') diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go index 26e1bf00b..a15fdb553 100644 --- a/pkg/api/handlers/compat/containers.go +++ b/pkg/api/handlers/compat/containers.go @@ -104,8 +104,12 @@ func ListContainers(w http.ResponseWriter, r *http.Request) { } filterMap, err := util.PrepareFilters(r) + if err != nil { + utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrapf(err, "failed to decode filter parameters for %s", r.URL.String())) + return + } - if dErr := decoder.Decode(&query, r.URL.Query()); dErr != nil || err != nil { + if err := decoder.Decode(&query, r.URL.Query()); err != nil { utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String())) return } -- cgit v1.2.3-54-g00ecf