Skip to content

Commit ed202fa

Browse files
authored
Add check for negative name indices in flamebearer profiles (#3324)
1 parent 24a46e4 commit ed202fa

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

pkg/og/structs/flamebearer/flamebearer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ func (fb FlamebearerProfileV1) Validate() error {
291291
if l[i] >= len(fb.Flamebearer.Names) {
292292
return fmt.Errorf("invalid name index %d, it should be smaller than %d", l[i], len(fb.Flamebearer.Levels))
293293
}
294+
if l[i] < 0 {
295+
return fmt.Errorf("invalid name index %d, it should be a non-negative value", l[i])
296+
}
294297
}
295298
}
296299
return nil

pkg/og/structs/flamebearer/flamebearer_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,21 @@ var _ = Describe("Checking profile validation", func() {
344344
})
345345
})
346346

347+
When("the name index is negative", func() {
348+
Context("and we validate a single profile", func() {
349+
var fb FlamebearerProfile
350+
BeforeEach(func() {
351+
fb.Metadata.Format = "single"
352+
fb.Flamebearer.Names = []string{"name"}
353+
fb.Flamebearer.Levels = [][]int{{0, 0, 0, -1}}
354+
})
355+
356+
It("returns an error", func() {
357+
Expect(fb.Validate()).To(MatchError("invalid name index -1, it should be a non-negative value"))
358+
})
359+
})
360+
})
361+
347362
When("everything is valid", func() {
348363
Context("and we validate a single profile", func() {
349364
var fb FlamebearerProfile

0 commit comments

Comments
 (0)