fix: go version not properly identified in binary (#1384)

This commit is contained in:
Keith Zantow
2022-12-02 13:24:36 -05:00
committed by GitHub
parent 247b054ab5
commit 614ea00905
4 changed files with 17 additions and 5 deletions
+7
View File
@@ -91,6 +91,12 @@ func fileNameTemplateVersionMatcher(fileNamePattern string, contentTemplate stri
}
}
func patternEndingWithNull(pattern string) string {
bytes := []byte(pattern)
bytes = append(bytes, 0)
return string(bytes)
}
func fileContentsVersionMatcher(pattern string) evidenceMatcher {
pat := regexp.MustCompile(pattern)
return func(classifier classifier, reader source.LocationReadCloser) ([]pkg.Package, error) {
@@ -130,6 +136,7 @@ func singlePackage(classifier classifier, reader source.LocationReadCloser, vers
Locations: source.NewLocationSet(reader.Location),
Type: pkg.BinaryPkg,
CPEs: cpes,
FoundBy: catalogerName,
MetadataType: pkg.BinaryMetadataType,
Metadata: pkg.BinaryMetadata{
Classifier: classifier.Class,
@@ -29,9 +29,10 @@ var defaultClassifiers = []classifier{
{
Class: "go-binary",
FileGlob: "**/go",
EvidenceMatcher: fileContentsVersionMatcher(
`(?m)go(?P<version>[0-9]+\.[0-9]+(\.[0-9]+|beta[0-9]+|alpha[0-9]+|rc[0-9]+)?)`),
EvidenceMatcher: fileContentsVersionMatcher(patternEndingWithNull(
`(?m)go(?P<version>[0-9]+\.[0-9]+(\.[0-9]+|beta[0-9]+|alpha[0-9]+|rc[0-9]+)?)`)),
Package: "go",
CPEs: singleCPE("cpe:2.3:a:golang:go:*:*:*:*:*:*:*:*"),
},
{
Class: "nodejs-binary",