Skip to content
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
5 changes: 4 additions & 1 deletion pkg/fanal/types/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"cmp"
"sort"
"strings"
"time"

"github.com/samber/lo"
Expand Down Expand Up @@ -71,7 +72,9 @@ func (o *OS) Merge(newOS OS) {
if o.Family == "" {
o.Family = newOS.Family
}
if o.Name == "" {
// One of the sources may report a shortened version, e.g. 7 and 7.9.2009 for CentOS.
// We always take the fullest version.
if o.Name == "" || (o.Family == newOS.Family && strings.HasPrefix(newOS.Name, o.Name+".")) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we bump the relevant analyzer version so that old cached OS results are not reused?

o.Name = newOS.Name
}
// Ubuntu has ESM program: https://ubuntu.com/security/esm
Expand Down
27 changes: 27 additions & 0 deletions pkg/fanal/types/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,33 @@ func TestOS_Merge(t *testing.T) {
newOS: OS{Family: Alpine, Name: "3.21.0"},
want: OS{Family: Alpine, Name: "3.20.3"},
},
{
// /etc/os-release yields 7, /etc/centos-release yields 7.9.2009.
// The analyzers run concurrently, so both orders must agree.
name: "more specific version wins",
os: OS{Family: CentOS, Name: "7"},
newOS: OS{Family: CentOS, Name: "7.9.2009"},
want: OS{Family: CentOS, Name: "7.9.2009"},
},
{
name: "less specific version loses",
os: OS{Family: CentOS, Name: "7.9.2009"},
newOS: OS{Family: CentOS, Name: "7"},
want: OS{Family: CentOS, Name: "7.9.2009"},
},
{
name: "a longer version that is not a refinement is ignored",
os: OS{Family: Alpine, Name: "3.2"},
newOS: OS{Family: Alpine, Name: "3.20"},
want: OS{Family: Alpine, Name: "3.2"},
},
{
// Versions of different families are unrelated, so one never refines the other.
name: "a longer version from another family is ignored",
os: OS{Family: Alpine, Name: "3"},
newOS: OS{Family: Wolfi, Name: "3.20"},
want: OS{Family: Alpine, Name: "3"},
},
{
name: "extended is sticky",
os: OS{Family: Ubuntu, Name: "18.04", Extended: true},
Expand Down