Skip to content

Commit eb89c8a

Browse files
committed
fix(osv): Improve error handling a bit
In particular, do not throw on CVSS version 4 vectors. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 36b3b10 commit eb89c8a

File tree

1 file changed

+9
-2
lines changed
  • plugins/advisors/osv/src/main/kotlin

1 file changed

+9
-2
lines changed

plugins/advisors/osv/src/main/kotlin/Osv.kt

+9-2
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,20 @@ private fun Vulnerability.toOrtVulnerability(): org.ossreviewtoolkit.model.vulne
194194
val url = reference.url.trim().let { if (it.startsWith("://")) "https$it" else it }
195195

196196
url.toUri().onFailure {
197-
logger.debug { "Could not parse reference URL for vulnerability '$id': ${it.message}." }
197+
logger.debug { "Could not parse reference URL for vulnerability '$id': ${it.collectMessages()}." }
198198
}.map {
199199
// Use the 'severity' property of the unspecified 'databaseSpecific' object.
200200
// See also https://github.com/google/osv.dev/issues/484.
201201
val specificSeverity = databaseSpecific?.get("severity")
202202

203-
val baseScore = Cvss.fromVector(severity)?.calculateScore()?.baseScore?.toFloat()
203+
// Note that the CVSS Calculator does not support CVSS 4.0 yet:
204+
// https://github.com/stevespringett/cvss-calculator/issues/78
205+
val baseScore = runCatching {
206+
Cvss.fromVector(severity)?.calculateScore()?.baseScore?.toFloat()
207+
}.onFailure {
208+
logger.debug { "Unable to parse CVSS vector '$severity': ${it.collectMessages()}." }
209+
}.getOrNull()
210+
204211
val severityRating = (specificSeverity as? JsonPrimitive)?.contentOrNull
205212
?: VulnerabilityReference.getQualitativeRating(scoringSystem, baseScore)?.name
206213

0 commit comments

Comments
 (0)