diff options
author | Sascha Grunert <sgrunert@redhat.com> | 2022-06-24 10:23:45 +0200 |
---|---|---|
committer | Bill Neubauer <bill.neubauer@gmail.com> | 2022-07-12 16:43:05 -0700 |
commit | c913e304a1534c4580fa70c2c3af5cd85d99fc9c (patch) | |
tree | 8e02c7da81214cc5016d69aeb690966d29d147da | |
parent | 7c62d6fe8d3aa2f39c4affb58c9781d9dc951a2d (diff) | |
download | licenseclassifier-c913e304a1534c4580fa70c2c3af5cd85d99fc9c.tar.gz |
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>
-rw-r--r-- | v2/classifier.go | 4 |
1 files changed, 4 insertions, 0 deletions
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 { |