From c913e304a1534c4580fa70c2c3af5cd85d99fc9c Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Fri, 24 Jun 2022 10:23:45 +0200 Subject: [PATCH] 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 --- v2/classifier.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/v2/classifier.go b/v2/classifier.go index 5e5f8cc..cb4eff6 100644 --- a/v2/classifier.go +++ b/v2/classifier.go @@ -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 {