Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP extensions binary classifiers #2585

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand the need for so many classifiers, can you help me understand what this is doing? (this should also probably be captured as a comment in the code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are extensions for which the source exists in the PHP codebase but aren't compiled in the main PHP binary. They are optionally compiled when users need it. ex: https://github.com/nextcloud/docker/blob/master/28/fpm-alpine/Dockerfile#L41-L53

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
Loading