Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions syft/pkg/cataloger/binary/elf_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,7 @@ func newELFPackage(metadata elfBinaryPackageNotes, locations file.LocationSet) p
func packageURL(metadata elfBinaryPackageNotes) string {
var qualifiers []packageurl.Qualifier

os := metadata.OS
osVersion := metadata.OSVersion

var atts cpe.Attributes
atts, err := cpe.NewAttributes(metadata.OSCPE)
if err != nil {
log.WithFields("error", err).Warn("unable to parse cpe attributes for elf binary package")
}
// only "upgrade" the OS information if there is something more specific to use in it's place
if os == "" && osVersion == "" || os == "" && atts.Version != "" || atts.Product != "" && osVersion == "" {
os = atts.Product
osVersion = atts.Version
}
os, osVersion := osNameAndVersionFromMetadata(metadata)

if os != "" {
osQualifier := os
Expand Down Expand Up @@ -70,6 +58,26 @@ func packageURL(metadata elfBinaryPackageNotes) string {
).ToString()
}

func osNameAndVersionFromMetadata(metadata elfBinaryPackageNotes) (string, string) {
os := metadata.OS
osVersion := metadata.OSVersion

if os != "" && osVersion != "" {
return os, osVersion
}

if metadata.OSCPE == "" {
return "", ""
}

attrs, err := cpe.NewAttributes(metadata.OSCPE)
if err != nil {
log.WithFields("error", err).Trace("unable to parse cpe attributes for elf binary package")
return "", ""
}
return attrs.Product, attrs.Version
}

const alpmType = "alpm"

func purlDistroType(ty string) string {
Expand Down
Loading