Skip to content

Commit 056d5d6

Browse files
committed
vex: warn and skip unparseable entries in knownAffectedVulnerabilities
The sibling functions fixedVulnerabilities and knownNotAffectedVulnerabilities already warn-and-skip on PackageName(), Module(), and cvssVectorFromScore() errors. This function was inadvertently changed to hard-fail during the iterator migration (f9fc989), causing a single bad entry in external VEX data to abort the entire update. Signed-off-by: J. Victor Martins <jvdm@sdf.org>
1 parent c46bb83 commit 056d5d6

3 files changed

Lines changed: 240 additions & 15 deletions

File tree

rhel/vex/parser.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -708,38 +708,42 @@ func (r *rope[E]) All() iter.Seq[*E] {
708708
// KnownAffectedVulnerabilities processes the "known_affected" array of products
709709
// in the VEX object.
710710
func (c *creator) knownAffectedVulnerabilities(ctx context.Context, v *csaf.Vulnerability, init vulnHook) ([]*claircore.Vulnerability, error) {
711+
log := slog.With("link", c.docLink)
711712
var backing rope[claircore.Vulnerability]
712713
for st, err := range c.Status(ctx, v, csaf.ProductStatusKnownAffected) {
713714
if err != nil {
714715
return nil, err
715716
}
716717

717-
// This loop never skips returned [status] values, so we can always just
718-
// append a new [claircore.Vulnerability].
719-
vuln := backing.New()
720-
721-
if err := init(ctx, vuln); err != nil {
722-
return nil, err
723-
}
724718
pkgName, err := st.PackageName()
725719
if err != nil {
726-
return nil, err
720+
log.WarnContext(ctx, "bad purl", "reason", err, "purl", st.PURL, "missing", "PackageName")
721+
continue
727722
}
728723
modName, err := st.Module()
729724
if err != nil {
725+
log.WarnContext(ctx, "bad purl", "reason", err, "purl", st.PURL, "missing", "ModuleName")
726+
continue
727+
}
728+
var sev string
729+
if sc := st.Score; sc != nil {
730+
sev, err = cvssVectorFromScore(sc)
731+
if err != nil {
732+
log.WarnContext(ctx, "bad score", "reason", err, "found", true)
733+
continue
734+
}
735+
}
736+
737+
vuln := backing.New()
738+
if err := init(ctx, vuln); err != nil {
730739
return nil, err
731740
}
732741
vuln.Package = &claircore.Package{
733742
Name: pkgName,
734743
Kind: types.SourcePackage, // Always source?
735744
Module: modName,
736745
}
737-
if sc := st.Score; sc != nil {
738-
vuln.Severity, err = cvssVectorFromScore(sc)
739-
if err != nil {
740-
return nil, fmt.Errorf("could not parse CVSS score: %w, file: %s", err, c.docLink)
741-
}
742-
}
746+
vuln.Severity = sev
743747
if t := st.Threat; t != nil {
744748
vuln.NormalizedSeverity = common.NormalizeSeverity(t.Details)
745749
}

rhel/vex/parser_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ func TestParse(t *testing.T) {
414414
expectedVulns: 269,
415415
expectedDeleted: 0,
416416
},
417+
{
418+
name: "bad_rpmmod_in_known_affected",
419+
filenames: []string{"testdata/cve-2024-24786-bad-rpmmod.json"},
420+
expectedVulns: 2,
421+
expectedDeleted: 0,
422+
},
417423
}
418424

419425
u := &Updater{url: url, client: http.DefaultClient}
@@ -686,4 +692,3 @@ func TestExtractPackageName(t *testing.T) {
686692
})
687693
}
688694
}
689-

rhel/vex/testdata/cve-2024-24786-bad-rpmmod.json

Lines changed: 216 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)