Skip to content

Commit

Permalink
🐛Fix conditions lexicographicLess nil pointer dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
m-messiah committed Oct 4, 2024
1 parent f88d7ae commit 072391d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions util/conditions/setter.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,17 @@ func Delete(to Setter, t clusterv1.ConditionType) {
to.SetConditions(newConditions)
}

// lexicographicLess returns true if a condition is less than another with regards to the
// to order of conditions designed for convenience of the consumer, i.e. kubectl.
// lexicographicLess returns true if a condition is less than another in regard to
// the order of conditions designed for convenience of the consumer, i.e. kubectl.
// According to this order the Ready condition always goes first, followed by all the other
// conditions sorted by Type.
func lexicographicLess(i, j *clusterv1.Condition) bool {
if i == nil {
return true
}
if j == nil {
return false
}
return (i.Type == clusterv1.ReadyCondition || i.Type < j.Type) && j.Type != clusterv1.ReadyCondition
}

Expand Down
6 changes: 6 additions & 0 deletions util/conditions/setter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ func TestLexicographicLess(t *testing.T) {
a = TrueCondition("A")
b = TrueCondition(clusterv1.ReadyCondition)
g.Expect(lexicographicLess(a, b)).To(BeFalse())

a = TrueCondition("A")
g.Expect(lexicographicLess(a, nil1)).To(BeFalse())

b = TrueCondition("A")
g.Expect(lexicographicLess(nil1, b)).To(BeTrue())
}

func TestSet(t *testing.T) {
Expand Down

0 comments on commit 072391d

Please sign in to comment.