Add support for reading ELF package notes with section header (#2939)

* add support for reading ELF package notes with section header

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* add systemd elf package fields to json schema

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman
2024-06-07 14:38:54 -04:00
committed by GitHub
parent bc20e66d08
commit 254a562b4e
10 changed files with 2862 additions and 69 deletions
+51 -4
View File
@@ -2,6 +2,7 @@ package binary
import (
"github.com/anchore/packageurl-go"
"github.com/anchore/syft/syft/cpe"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/pkg"
)
@@ -23,13 +24,59 @@ func newELFPackage(metadata elfBinaryPackageNotes, locations file.LocationSet) p
}
func packageURL(metadata elfBinaryPackageNotes) string {
// TODO: what if the System value is not set?
var qualifiers []packageurl.Qualifier
os := metadata.OS
osVersion := metadata.OSVersion
atts, err := cpe.NewAttributes(metadata.OSCPE)
if err == nil {
// 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 != "" {
osQualifier := os
if osVersion != "" {
osQualifier += "-" + osVersion
}
qualifiers = append(qualifiers, packageurl.Qualifier{
Key: "distro",
Value: osQualifier,
})
}
ty := purlDistroType(metadata.Type)
namespace := os
if ty == packageurl.TypeGeneric || os == "" {
namespace = metadata.System
}
return packageurl.NewPackageURL(
packageurl.TypeGeneric,
metadata.System,
ty,
namespace,
metadata.Name,
metadata.Version,
nil,
qualifiers,
"",
).ToString()
}
func purlDistroType(ty string) string {
switch ty {
case "rpm":
return packageurl.TypeRPM
case "deb":
return packageurl.TypeDebian
case "apk":
return packageurl.TypeAlpine
case "alpm":
return "alpm"
}
return packageurl.TypeGeneric
}