From 7370fb2772672e0f2ecf7a081d3f655b5a730c31 Mon Sep 17 00:00:00 2001 From: Christian Zunker <827818+czunker@users.noreply.github.com> Date: Fri, 12 Jan 2024 09:07:23 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Do=20not=20exit=20on=20time=20pa?= =?UTF-8?q?rse=20errors=20(#3002)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some CVEs do not have a publish or modified date. Do not exit in these case. Fixes #2995 Signed-off-by: Christian Zunker --- providers/os/resources/vulnmgmt.go | 38 ++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/providers/os/resources/vulnmgmt.go b/providers/os/resources/vulnmgmt.go index 85a095b28c..e41d4d98c9 100644 --- a/providers/os/resources/vulnmgmt.go +++ b/providers/os/resources/vulnmgmt.go @@ -102,13 +102,20 @@ func (v *mqlVulnmgmt) populateData() error { mqlVulAdvisories := make([]interface{}, len(vulnReport.Advisories)) for i, a := range vulnReport.Advisories { - parsedPublished, err := time.Parse(time.RFC3339, a.PublishedAt) + var parsedPublished *time.Time + var parsedModifed *time.Time + var err error + published, err := time.Parse(time.RFC3339, a.PublishedAt) if err != nil { - return err + log.Debug().Str("date", a.PublishedAt).Str("advisory", a.Id).Msg("could not parse published date") + } else { + parsedPublished = &published } - parsedModifed, err := time.Parse(time.RFC3339, a.ModifiedAt) + modified, err := time.Parse(time.RFC3339, a.ModifiedAt) if err != nil { - return err + log.Debug().Str("date", a.ModifiedAt).Str("advisory", a.Id).Msg("could not parse modified date") + } else { + parsedModifed = &modified } cvssScore, err := CreateResource(v.MqlRuntime, "audit.cvss", map[string]*llx.RawData{ "score": llx.FloatData(float64(a.CvssScore.Value) / 10), @@ -121,8 +128,8 @@ func (v *mqlVulnmgmt) populateData() error { "id": llx.StringData(a.Id), "title": llx.StringData(a.Title), "description": llx.StringData(a.Description), - "published": llx.TimeData(parsedPublished), - "modified": llx.TimeData(parsedModifed), + "published": llx.TimeDataPtr(parsedPublished), + "modified": llx.TimeDataPtr(parsedModifed), "worstScore": llx.ResourceData(cvssScore, "audit.cvss"), }) if err != nil { @@ -133,13 +140,20 @@ func (v *mqlVulnmgmt) populateData() error { mqlVulnCves := make([]interface{}, len(vulnReport.Cves)) for i, c := range vulnReport.Cves { - parsedPublished, err := time.Parse(time.RFC3339, c.PublishedAt) + var parsedPublished *time.Time + var parsedModifed *time.Time + var err error + published, err := time.Parse(time.RFC3339, c.PublishedAt) if err != nil { - return err + log.Debug().Str("date", c.PublishedAt).Str("cve", c.Id).Msg("could not parse published date") + } else { + parsedPublished = &published } - parsedModifed, err := time.Parse(time.RFC3339, c.ModifiedAt) + modified, err := time.Parse(time.RFC3339, c.ModifiedAt) if err != nil { - return err + log.Debug().Str("date", c.ModifiedAt).Str("cve", c.Id).Msg("could not parse modified date") + } else { + parsedModifed = &modified } cvssScore, err := CreateResource(v.MqlRuntime, "audit.cvss", map[string]*llx.RawData{ "score": llx.FloatData(float64(c.CvssScore.Value) / 10), @@ -151,8 +165,8 @@ func (v *mqlVulnmgmt) populateData() error { mqlVulnCve, err := CreateResource(v.MqlRuntime, "vuln.cve", map[string]*llx.RawData{ "id": llx.StringData(c.Id), "worstScore": llx.ResourceData(cvssScore, "audit.cvss"), - "published": llx.TimeData(parsedPublished), - "modified": llx.TimeData(parsedModifed), + "published": llx.TimeDataPtr(parsedPublished), + "modified": llx.TimeDataPtr(parsedModifed), }) if err != nil { return err