mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 15:36:41 +01:00
Only match ldflag version if it matches the main module or targets main.version (#3062)
Signed-off-by: Laurent Goderre <laurent.goderre@docker.com>
This commit is contained in:
@@ -208,7 +208,7 @@ func (c *goBinaryCataloger) findMainModuleVersion(metadata *pkg.GolangBinaryBuil
|
||||
// version of the package.
|
||||
ldflags, _ = metadata.BuildSettings.Get("-ldflags")
|
||||
|
||||
majorVersion, fullVersion = extractVersionFromLDFlags(ldflags)
|
||||
majorVersion, fullVersion = extractVersionFromLDFlags(ldflags, metadata.MainModule)
|
||||
if fullVersion != "" {
|
||||
return fullVersion
|
||||
}
|
||||
@@ -258,13 +258,14 @@ func extractVersionFromContents(reader io.Reader) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func extractVersionFromLDFlags(ldflags string) (majorVersion string, fullVersion string) {
|
||||
func extractVersionFromLDFlags(ldflags string, maimModule string) (majorVersion string, fullVersion string) {
|
||||
if ldflags == "" {
|
||||
return "", ""
|
||||
}
|
||||
|
||||
for _, pattern := range knownBuildFlagPatterns {
|
||||
groups := internal.MatchNamedCaptureGroups(pattern, ldflags)
|
||||
newPattern := regexp.MustCompile(fmt.Sprintf(`(main|%s\/[^\s]*)%s`, strings.ReplaceAll(maimModule, "/", "\\/"), pattern.String()))
|
||||
groups := internal.MatchNamedCaptureGroups(newPattern, ldflags)
|
||||
v, ok := groups["version"]
|
||||
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user