Skip to content

Commit

Permalink
fix: update cataloger to check for expressions before split (anchore#…
Browse files Browse the repository at this point in the history
…1819)

Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
  • Loading branch information
spiffcs authored May 16, 2023
1 parent e2ad2ca commit 814f55e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion syft/pkg/cataloger/apkdb/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import (
"strings"

"github.com/anchore/packageurl-go"
"github.com/anchore/syft/syft/license"
"github.com/anchore/syft/syft/linux"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/source"
)

func newPackage(d parsedData, release *linux.Release, dbLocation source.Location) pkg.Package {
licenseStrings := strings.Split(d.License, " ")
// check if license is a valid spdx expression before splitting
licenseStrings := []string{d.License}
_, err := license.ParseExpression(d.License)
if err != nil {
// invalid so update to split on space
licenseStrings = strings.Split(d.License, " ")
}

p := pkg.Package{
Name: d.Package,
Expand Down
2 changes: 1 addition & 1 deletion syft/pkg/cataloger/apkdb/parse_apk_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func TestMultiplePackages(t *testing.T) {
Name: "libc-utils",
Version: "0.7.2-r0",
Licenses: pkg.NewLicenseSet(
pkg.NewLicenseFromLocations("BSD", location),
pkg.NewLicenseFromLocations("MPL-2.0 AND MIT", location),
),
Type: pkg.ApkPkg,
PURL: "pkg:apk/alpine/libc-utils@0.7.2-r0?arch=x86_64&upstream=libc-dev&distro=alpine-3.12",
Expand Down
2 changes: 1 addition & 1 deletion syft/pkg/cataloger/apkdb/test-fixtures/multiple
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ S:1175
I:4096
T:Meta package to pull in correct libc
U:http://alpinelinux.org
L:BSD
L:MPL-2.0 AND MIT
o:libc-dev
m:Natanael Copa <ncopa@alpinelinux.org>
t:1575749004
Expand Down

0 comments on commit 814f55e

Please # to comment.