Skip to content

Commit c913e30

Browse files
saschagrunertwcn3
authored andcommitted
Fix runtime panic on LoadLicenses()
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>
1 parent 7c62d6f commit c913e30

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

v2/classifier.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ func (c *Classifier) LoadLicenses(dir string) error {
287287
relativePath := strings.Replace(f, dir, "", 1)
288288
sep := fmt.Sprintf("%c", os.PathSeparator)
289289
segments := strings.Split(relativePath, sep)
290+
if len(segments) < 3 {
291+
c.tc.trace("Insufficient segment count for path: %s", relativePath)
292+
continue
293+
}
290294
category, name, variant := segments[1], segments[2], segments[3]
291295
b, err := ioutil.ReadFile(f)
292296
if err != nil {

0 commit comments

Comments
 (0)