From 9af69bcd743a6f3c911d9a9906a5c14361face60 Mon Sep 17 00:00:00 2001 From: acmarr Date: Tue, 10 Dec 2024 16:34:53 -0800 Subject: [PATCH] adjusted openssl fetcher to handle new page format --- updater/fetchers/apps/apps_test.go | 17 ++++++----------- updater/fetchers/apps/openssl.go | 29 ++++++++++++----------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/updater/fetchers/apps/apps_test.go b/updater/fetchers/apps/apps_test.go index 572f01e..15fc8e5 100644 --- a/updater/fetchers/apps/apps_test.go +++ b/updater/fetchers/apps/apps_test.go @@ -32,21 +32,16 @@ func TestRubyAffectedVersion(t *testing.T) { func TestOpensslVulVersion(t *testing.T) { lines := []string{ - "", - "", - "", - "", + "
  • from 1.0.1 before 1.0.1u
  • ", + "
  • from 1.0.2 before 1.0.2i
  • \n
  • from 1.0.4 before 1.0.5d
  • ", } affected := [][]common.AppModuleVersion{ []common.AppModuleVersion{ - {"lt", "3.2.2"}, {"gteq", "3.2.0"}, {"orlt", "3.1.6"}, {"gteq", "3.1.0"}, - {"orlt", "3.0.14"}, {"gteq", "3.0.0"}, {"orlt", "1.1.1y"}, {"gteq", "1.1.1"}}, + {"lt", "1.0.1u"}, {"gteq", "1.0.1"}, + }, []common.AppModuleVersion{ - {"lt", "0.9.8h"}, {"gteq", "0.9.8f"}}, - []common.AppModuleVersion{ - {"lt", "fips-1.1.2"}, {"gteq", "fips-1.1.1"}}, - []common.AppModuleVersion{ - {"lt", "0.9.8j"}, {"gteq", "0.9.8"}}, + {"lt", "1.0.2i"}, {"gteq", "1.0.2"}, {"orlt", "1.0.5d"}, {"gteq", "1.0.4"}, + }, } for i, line := range lines { diff --git a/updater/fetchers/apps/openssl.go b/updater/fetchers/apps/openssl.go index 102e987..26cb978 100644 --- a/updater/fetchers/apps/openssl.go +++ b/updater/fetchers/apps/openssl.go @@ -20,8 +20,9 @@ const ( var cveNameRegexp = regexp.MustCompile(`="(.*)">CVE-([0-9\-]+)`) var fixedVerRegexp = regexp.MustCompile(`Fixed in OpenSSL\s*\n*([0-9a-z\.\-\s]+)`) var affectedVerRegexp = regexp.MustCompile(`\(Affected\s+([0-9a-z\.\-,\s]+)\s*\)`) -var verRegexp = regexp.MustCompile(`Fixed in OpenSSL\s*\n*([0-9a-z\.\-\s]+).*?\(Affected\s+([0-9a-z\.\-,\s]+)\s*\)`) // ungreedy -var severityRegexp = regexp.MustCompile(`[[a-zA-Z]+ severity]`) +var verRegexp = regexp.MustCompile(`
  • from\s*\n*([0-9a-z\.\-\s]+) before\s*\n*([0-9a-z\.\-\s]+)<\/li>`) // ungreedy +var severityRegexp = regexp.MustCompile(`
    Severity<\/dt>[\S+\n\r\s]+
    ([a-zA-Z]+)<\/dd>`) +var descriptionRegexp = regexp.MustCompile(`

    ([a-zA-Z[\S+\n\r\s]+)<\/p>`) // FetchUpdate gets vulnerability updates from the openssl. func opensslUpdate() error { @@ -70,21 +71,14 @@ func opensslUpdate() error { match = severityRegexp.FindAllStringSubmatch(line, -1) if len(match) > 0 { - s := match[0] - severityStr := strings.Split(s[0], " ")[0] - severityStr = strings.Replace(severityStr, "[", "", 1) - severity = severityStr + severity = match[0][1] } else { continue } - a0 := strings.Index(line, "

    ") - a1 := strings.Index(line, "

      ") - if a0 > 0 && a1 > a0 { - description = line[a0+3 : a1] - description = strings.ReplaceAll(description, "

      ", "") - description = strings.ReplaceAll(description, "

      ", "") - description = strings.ReplaceAll(description, "\n", "") + match = descriptionRegexp.FindAllStringSubmatch(line, -1) + if len(match) > 0 { + description = match[0][1] } else { log.Error("No description:", line) continue @@ -132,17 +126,18 @@ func getOpensslVulVersion(cve, line string) ([]common.AppModuleVersion, []common for i, m := range match { if len(m) >= 2 { - fv := strings.TrimSpace(m[1]) + fv := strings.TrimSpace(m[2]) fver = append(fver, common.AppModuleVersion{Version: fv}) var av string - if strings.HasPrefix(m[2], "since ") { - av = strings.TrimSpace(strings.TrimSpace(m[2][6:])) + if strings.HasPrefix(m[1], "since ") { + av = strings.TrimSpace(strings.TrimSpace(m[1][6:])) } else { - av = strings.TrimSpace(strings.TrimSpace(m[2])) + av = strings.TrimSpace(strings.TrimSpace(m[1])) } if i == 0 { + fv := strings.TrimSpace(m[2]) aver = append(aver, common.AppModuleVersion{OpCode: "lt", Version: fv}) } else { aver = append(aver, common.AppModuleVersion{OpCode: "orlt", Version: fv})