Skip to content

Commit 072391d

Browse files
committed
🐛Fix conditions lexicographicLess nil pointer dereference
1 parent f88d7ae commit 072391d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

util/conditions/setter.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,17 @@ func Delete(to Setter, t clusterv1.ConditionType) {
186186
to.SetConditions(newConditions)
187187
}
188188

189-
// lexicographicLess returns true if a condition is less than another with regards to the
190-
// to order of conditions designed for convenience of the consumer, i.e. kubectl.
189+
// lexicographicLess returns true if a condition is less than another in regard to
190+
// the order of conditions designed for convenience of the consumer, i.e. kubectl.
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)