Skip to content

Commit e9be8cc

Browse files
authored
Merge pull request #11255 from m-messiah/nil-pointer-check-for-less
🐛Fix conditions lexicographicLess nil pointer dereference
2 parents 2beebbd + 072391d commit e9be8cc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

util/conditions/setter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ func Delete(to Setter, t clusterv1.ConditionType) {
191191
// According to this order the Ready condition always goes first, followed by all the other
192192
// conditions sorted by Type.
193193
func lexicographicLess(i, j *clusterv1.Condition) bool {
194+
if i == nil {
195+
return true
196+
}
197+
if j == nil {
198+
return false
199+
}
194200
return (i.Type == clusterv1.ReadyCondition || i.Type < j.Type) && j.Type != clusterv1.ReadyCondition
195201
}
196202

util/conditions/setter_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ func TestLexicographicLess(t *testing.T) {
8484
a = TrueCondition("A")
8585
b = TrueCondition(clusterv1.ReadyCondition)
8686
g.Expect(lexicographicLess(a, b)).To(BeFalse())
87+
88+
a = TrueCondition("A")
89+
g.Expect(lexicographicLess(a, nil1)).To(BeFalse())
90+
91+
b = TrueCondition("A")
92+
g.Expect(lexicographicLess(nil1, b)).To(BeTrue())
8793
}
8894

8995
func TestSet(t *testing.T) {

0 commit comments

Comments
 (0)