// Collect CVE-IDs included in the changelog. // The version which specified in argument(versionOrLater) is excluded. func (o *debian) parseChangelog(changelog string, packName string, versionOrLater string) (cveIDs []string, err error) { cveRe := regexp.MustCompile(`(CVE-\d{4}-\d{4,})`) stopRe := regexp.MustCompile(fmt.Sprintf(`\(%s\)`, regexp.QuoteMeta(versionOrLater))) stopLineFound := false lines := strings.Split(changelog, "\n") for _, line := range lines { if matche := stopRe.MatchString(line); matche { // o.log.Debugf("Found the stop line: %s", line) stopLineFound = true break } else if matches := cveRe.FindAllString(line, -1); 0 < len(matches) { for _, m := range matches { cveIDs = util.AppendIfMissing(cveIDs, m) } } } if !stopLineFound { return []string{}, fmt.Errorf( "Failed to scan CVE IDs. The version is not in changelog. name: %s, version: %s", packName, versionOrLater, ) } return }
func scanVulnByCpeNames(cpeNames []string, scannedVulns []models.VulnInfo) ([]models.VulnInfo, error) { // To remove duplicate set := map[string]models.VulnInfo{} for _, v := range scannedVulns { set[v.CveID] = v } for _, name := range cpeNames { details, err := cveapi.CveClient.FetchCveDetailsByCpeName(name) if err != nil { return nil, err } for _, detail := range details { if val, ok := set[detail.CveID]; ok { names := val.CpeNames names = util.AppendIfMissing(names, name) val.CpeNames = names set[detail.CveID] = val } else { set[detail.CveID] = models.VulnInfo{ CveID: detail.CveID, CpeNames: []string{name}, } } } } vinfos := []models.VulnInfo{} for key := range set { vinfos = append(vinfos, set[key]) } return vinfos, nil }