aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-01-31 22:16:23 -0500
committerPaul Duncan <pabs@pablotron.org>2022-01-31 22:16:23 -0500
commit5c4ff27a0bc70cdefad0c9a68e920e480465c4d9 (patch)
tree1cad646424696fab83956d2f042d00551228d962
parent6b80bfb7889444cdb9ab07dcd5fe2fcb2000ce8e (diff)
downloadcvez-5c4ff27a0bc70cdefad0c9a68e920e480465c4d9.tar.bz2
cvez-5c4ff27a0bc70cdefad0c9a68e920e480465c4d9.zip
internal/cvss: handle invalid keys and metrics
-rw-r--r--internal/cvss/v2key.go12
-rw-r--r--internal/cvss/v2metric.go7
-rw-r--r--internal/cvss/v3key.go12
-rw-r--r--internal/cvss/v3metric.go7
4 files changed, 30 insertions, 8 deletions
diff --git a/internal/cvss/v2key.go b/internal/cvss/v2key.go
index 26ee200..740d26d 100644
--- a/internal/cvss/v2key.go
+++ b/internal/cvss/v2key.go
@@ -75,10 +75,18 @@ var v2Keys = map[v2Key]struct {
// Get metric key name.
func (k v2Key) Name() string {
- return v2Keys[k].Name
+ if data, ok := v2Keys[k]; ok {
+ return data.Name
+ } else {
+ return "invalid"
+ }
}
// Get metric key category.
func (k v2Key) Category() Category {
- return v2Keys[k].Category
+ if data, ok := v2Keys[k]; ok {
+ return data.Category
+ } else {
+ return InvalidCategory
+ }
}
diff --git a/internal/cvss/v2metric.go b/internal/cvss/v2metric.go
index a80cf8a..2dee41a 100644
--- a/internal/cvss/v2metric.go
+++ b/internal/cvss/v2metric.go
@@ -236,6 +236,9 @@ func getV2Metric(s string) (v2Metric, error) {
// Get CVSS 2.0 metric key.
func (m v2Metric) Key() Key {
- k, _ := v2KeyLut[m]
- return k
+ if k, ok := v2KeyLut[m]; ok {
+ return k
+ } else {
+ return v2InvalidKey
+ }
}
diff --git a/internal/cvss/v3key.go b/internal/cvss/v3key.go
index f1f32cd..653c2da 100644
--- a/internal/cvss/v3key.go
+++ b/internal/cvss/v3key.go
@@ -99,10 +99,18 @@ var v3Keys = map[v3Key]struct {
// Get metric key name.
func (k v3Key) Name() string {
- return v3Keys[k].Name
+ if data, ok := v3Keys[k]; ok {
+ return data.Name
+ } else {
+ return "invalid"
+ }
}
// Get metric key category.
func (k v3Key) Category() Category {
- return v3Keys[k].Category
+ if data, ok := v3Keys[k]; ok {
+ return data.Category
+ } else {
+ return InvalidCategory
+ }
}
diff --git a/internal/cvss/v3metric.go b/internal/cvss/v3metric.go
index a8f25de..e9a6763 100644
--- a/internal/cvss/v3metric.go
+++ b/internal/cvss/v3metric.go
@@ -314,8 +314,11 @@ var v3MetricStrLut = map[string]v3Metric {
// Get CVSS 3.x metric key.
func (m v3Metric) Key() Key {
- k, _ := v3KeyLut[m]
- return k
+ if k, ok := v3KeyLut[m]; ok {
+ return k
+ } else {
+ return v3InvalidKey
+ }
}
// Convert string to CVSS 3.1 metric.