Skip to content

Commit

Permalink
fix nil pointer dereference when parsing config map (#1096)
Browse files Browse the repository at this point in the history
Co-authored-by: Izabela Gomes <[email protected]>
  • Loading branch information
knative-prow-robot and izabelacg authored May 23, 2024
1 parent f3bb986 commit 52fe7b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/reconciler/contour/config/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/reconciler/contour/config/contour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 52fe7b4

Please sign in to comment.