mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
fix: stop some log.Warn spam due parsing an empty string as a CPE (#3330)
* chore: don't try to parse empty string as CPE Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com> * chore: improve OS name and version extraction from ELF metadata Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com> --------- Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com>
This commit is contained in:
parent
138c6e3420
commit
754cebee64
@ -27,19 +27,7 @@ func newELFPackage(metadata elfBinaryPackageNotes, locations file.LocationSet) p
|
|||||||
func packageURL(metadata elfBinaryPackageNotes) string {
|
func packageURL(metadata elfBinaryPackageNotes) string {
|
||||||
var qualifiers []packageurl.Qualifier
|
var qualifiers []packageurl.Qualifier
|
||||||
|
|
||||||
os := metadata.OS
|
os, osVersion := osNameAndVersionFromMetadata(metadata)
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if os != "" {
|
if os != "" {
|
||||||
osQualifier := os
|
osQualifier := os
|
||||||
@ -70,6 +58,26 @@ func packageURL(metadata elfBinaryPackageNotes) string {
|
|||||||
).ToString()
|
).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"
|
const alpmType = "alpm"
|
||||||
|
|
||||||
func purlDistroType(ty string) string {
|
func purlDistroType(ty string) string {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user