Skip to content

Commit

Permalink
Fix runtime panic on LoadLicenses()
Browse files Browse the repository at this point in the history
It may be possible that the amount of segments is lower than 3 which
caused a runtime panic in the license loader. We now skip those paths to
fix that issue.

Found: https://github.com/cri-o/cri-o/runs/7037925519

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert authored and wcn3 committed Jul 12, 2022
1 parent 7c62d6f commit c913e30
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions v2/classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ func (c *Classifier) LoadLicenses(dir string) error {
relativePath := strings.Replace(f, dir, "", 1)
sep := fmt.Sprintf("%c", os.PathSeparator)
segments := strings.Split(relativePath, sep)
if len(segments) < 3 {
c.tc.trace("Insufficient segment count for path: %s", relativePath)
continue
}
category, name, variant := segments[1], segments[2], segments[3]
b, err := ioutil.ReadFile(f)
if err != nil {
Expand Down

0 comments on commit c913e30

Please sign in to comment.