Skip to content

Commit 935e1de

Browse files
k8s-infra-cherrypick-robotwooffieGacko
authored
Controller: Fix nil pointer in path validation. (#13681)
Co-authored-by: Burkov Egor <[email protected]> Co-authored-by: Marco Ebert <[email protected]>
1 parent 06dbdc7 commit 935e1de

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

internal/ingress/inspector/inspector.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ func ValidatePathType(ing *networking.Ingress) error {
5555
}
5656
if path.PathType == nil || *path.PathType != implSpecific {
5757
if isValid := validPathType.MatchString(path.Path); !isValid {
58-
err = errors.Join(err, fmt.Errorf("path %s cannot be used with pathType %s", path.Path, string(*path.PathType)))
58+
var pathTypeStr string
59+
if path.PathType != nil {
60+
pathTypeStr = string(*path.PathType)
61+
} else {
62+
pathTypeStr = "<nil>"
63+
}
64+
err = errors.Join(err, fmt.Errorf("path %s cannot be used with pathType %s", path.Path, pathTypeStr))
5965
}
6066
}
6167
}

internal/ingress/inspector/inspector_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ var (
101101
PathType: &prefix,
102102
Path: "/lala/xp\ntest",
103103
},
104+
{
105+
Path: "notvalidpathname-panics",
106+
},
104107
},
105108
},
106109
},
@@ -174,6 +177,7 @@ func TestValidatePathType(t *testing.T) {
174177
aErr("xpto/lala", "Exact"),
175178
aErr("/foo/bar/[a-z]{3}", "Prefix"),
176179
aErr("/lala/xp\ntest", "Prefix"),
180+
aErr("notvalidpathname-panics", "<nil>"),
177181
),
178182
},
179183
}

0 commit comments

Comments
 (0)