Skip to content

Commit

Permalink
combine-to-osv expects an array of PackageInfo not a single struct (#…
Browse files Browse the repository at this point in the history
…1534)

Emit an array so it doesn't crash on the non-array input
  • Loading branch information
andrewpollock authored Aug 7, 2023
1 parent ac220d0 commit 723e326
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions vulnfeeds/cpp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ func CVEToPackageInfo(CVE cves.CVEItem, repos []string, cache git.RepoTagsCache,
return fmt.Errorf("[%s]: No affected commit ranges determined for %q", CVEID, CPE.Product)
}

var pkgInfos []vulns.PackageInfo
pi := vulns.PackageInfo{VersionInfo: versions}
pkgInfos = append(pkgInfos, pi) // combine-to-osv expects a serialised *array* of PackageInfo

vulnDir := filepath.Join(directory, CPE.Vendor, CPE.Product)
err = os.MkdirAll(vulnDir, 0755)
Expand All @@ -314,11 +316,13 @@ func CVEToPackageInfo(CVE cves.CVEItem, repos []string, cache git.RepoTagsCache,
}
defer f.Close()

err = pi.ToJSON(f)
encoder := json.NewEncoder(f)
encoder.SetIndent("", " ")
err = encoder.Encode(&pkgInfos)

if err != nil {
Logger.Warnf("Failed to write %s: %v", outputFile, err)
return fmt.Errorf("failed to write %s: %v", outputFile, err)
Logger.Warnf("Failed to encode PackageInfo to %s: %v", outputFile, err)
return fmt.Errorf("failed to encode PackageInfo to %s: %v", outputFile, err)
}

Logger.Infof("[%s]: Generated PackageInfo record from for %q", CVEID, CPE.Product)
Expand Down

0 comments on commit 723e326

Please sign in to comment.