Skip to content

Commit

Permalink
Add PHP extensions binary classifiers
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Goderre <laurent.goderre@docker.com>
  • Loading branch information
LaurentGoderre committed Feb 5, 2024
1 parent 3023a5a commit 09c74c3
Show file tree
Hide file tree
Showing 50 changed files with 428 additions and 1 deletion.
92 changes: 91 additions & 1 deletion syft/pkg/cataloger/binary/default_classifiers.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package binary

import (
"fmt"

"github.com/anchore/syft/syft/cpe"
)

//nolint:funlen
func DefaultClassifiers() []Classifier {
return []Classifier{
classifiers := []Classifier{
{
Class: "python-binary",
FileGlob: "**/python*",
Expand Down Expand Up @@ -415,6 +417,94 @@ func DefaultClassifiers() []Classifier {
CPEs: singleCPE("cpe:2.3:a:wp-cli:wp-cli:*:*:*:*:*:*:*:*"),
},
}

classifiers = append(classifiers, phpExtensionsClassifiers()...)

return classifiers
}

//nolint:funlen
func phpExtensionsClassifiers() []Classifier {
classifiers := make([]Classifier, 0)

extensions := []string{
"bcmath",
"bz2",
"calendar",
"ctype",
"curl",
"dba",
"dl_test",
// "dom",
"enchant",
"exif",
"ffi",
"fileinfo",
"filter",
"ftp",
"gd",
"gettext",
"gmp",
"iconv",
"intl",
"ldap",
"mbstring",
"mysqli",
"odbc",
"opcache",
"pcntl",
"pdo_dblib",
"pdo_firebird",
"pdo_mysql",
"pdo_odbc",
"pdo_pgsql",
"pgsql",
"phar",
"posix",
"session",
"shmop",
"simplexml",
"snmp",
"soap",
"sockets",
"sodium",
"sysvmsg",
"sysvsem",
"sysvshm",
"tidy",
"xml",
"xmlreader",
"xmlwriter",
"xsl",
"zip",
}

for _, ext := range extensions {
match := ""

switch ext {
// TODO: case "dom:"
case "mysqli":
match = `mysqlnd (?P<version>[0-9]+\.[0-9]+\.[0-9]+)\x00{2}`
case "opcache":
match = `overflow\x00+(?P<version>[0-9]+\.[0-9]+\.[0-9]+)\x00{2}Zend`
case "zip":
match = `\x00+(?P<version>[0-9]+\.[0-9]+\.[0-9]+)\x00{2}Zip`
default:
match = fmt.Sprintf(`(?m)(\x00+%s)?\x00+(?P<version>[0-9]+\.[0-9]+\.[0-9]+)\x00{2}API`, ext)
}

classifiers = append(classifiers, Classifier{
Class: fmt.Sprintf("php-ext-%s-binary", ext),
FileGlob: fmt.Sprintf("**/%s.so", ext),
EvidenceMatcher: FileContentsVersionMatcher(match),
Package: ext,
PURL: mustPURL(fmt.Sprintf("pkg:generic/%s@version", ext)),
CPEs: singleCPE("cpe:2.3:a:php:php:*:*:*:*:*:*:*:*"),
})
}

return classifiers
}

// in both binaries and shared libraries, the version pattern is [NUL]3.11.2[NUL]
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 09c74c3

Please sign in to comment.