From 1416c53276939dd8de448074f9d6134cd3916fb2 Mon Sep 17 00:00:00 2001 From: Izabela Gomes Date: Wed, 22 May 2024 17:59:12 -0400 Subject: [PATCH] fix nil pointer dereference when parsing config map (#1095) --- pkg/reconciler/contour/config/contour.go | 2 +- pkg/reconciler/contour/config/contour_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/reconciler/contour/config/contour.go b/pkg/reconciler/contour/config/contour.go index e27fc0f27..efe8a16b3 100644 --- a/pkg/reconciler/contour/config/contour.go +++ b/pkg/reconciler/contour/config/contour.go @@ -81,7 +81,7 @@ func NewContourFromConfigMap(configMap *corev1.ConfigMap) (*Contour, error) { return nil, err } - if len(contourCORSPolicy.AllowOrigin) == 0 || len(contourCORSPolicy.AllowMethods) == 0 { + if contourCORSPolicy == nil || len(contourCORSPolicy.AllowOrigin) == 0 || len(contourCORSPolicy.AllowMethods) == 0 { return nil, fmt.Errorf("the following fields are required but are missing or empty: %s.allowOrigin and %s.allowMethods", corsPolicy, corsPolicy) } diff --git a/pkg/reconciler/contour/config/contour_test.go b/pkg/reconciler/contour/config/contour_test.go index 94e4a33ab..ca9bc18be 100644 --- a/pkg/reconciler/contour/config/contour_test.go +++ b/pkg/reconciler/contour/config/contour_test.go @@ -174,6 +174,18 @@ maxAge: "10m" `, }, }, + }, { + name: "empty configuration", + wantErr: true, + config: &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: system.Namespace(), + Name: ContourConfigName, + }, + Data: map[string]string{ + corsPolicy: "", + }, + }, }, { name: "wrong option", wantErr: true,