Greenbone Vulnerability Management Libraries  11.0.0
cvss.h File Reference

Protos for CVSS utility functions. More...

#include <glib.h>
Include dependency graph for cvss.h:

Go to the source code of this file.

Functions

double get_cvss_score_from_base_metrics (const char *)
 Calculate CVSS Score. More...
 

Detailed Description

Protos for CVSS utility functions.

This file contains the protos for cvss.c

Definition in file cvss.h.

Function Documentation

◆ get_cvss_score_from_base_metrics()

double get_cvss_score_from_base_metrics ( const char *  cvss_str)

Calculate CVSS Score.

Parameters
cvss_strBase vector string from which to compute score.
Returns
The resulting score. -1 upon error during parsing.

Definition at line 342 of file cvss.c.

343 {
344  struct cvss cvss;
345  char *token, *base_str, *base_metrics;
346 
347  memset (&cvss, 0x00, sizeof (struct cvss));
348 
349  if (cvss_str == NULL)
350  return -1.0;
351 
352  base_str = base_metrics = g_strdup_printf ("%s/", cvss_str);
353 
354  while ((token = strchr (base_metrics, '/')) != NULL)
355  {
356  char *token2 = strtok (base_metrics, ":");
357  char *metric_name = token2;
358  char *metric_value;
359  enum base_metrics mval;
360  int rc;
361 
362  *token++ = '\0';
363 
364  if (metric_name == NULL)
365  goto ret_err;
366 
367  metric_value = strtok (NULL, ":");
368 
369  if (metric_value == NULL)
370  goto ret_err;
371 
372  rc = toenum (metric_name, &mval);
373  if (rc)
374  goto ret_err;
375 
376  if (set_impact_from_str (metric_value, mval, &cvss))
377  goto ret_err;
378 
379  base_metrics = token;
380  }
381 
382  g_free (base_str);
383  return __get_cvss_score (&cvss);
384 
385 ret_err:
386  g_free (base_str);
387  return (double) -1;
388 }

References __get_cvss_score(), set_impact_from_str(), and toenum().

Here is the call graph for this function:
__get_cvss_score
static double __get_cvss_score(struct cvss *cvss)
Final CVSS score computation helper.
Definition: cvss.c:318
toenum
static int toenum(const char *str, enum base_metrics *res)
Determine base metric enumeration from a string.
Definition: cvss.c:195
cvss
Describe a CVSS metrics.
Definition: cvss.c:137
base_metrics
base_metrics
Base metrics.
Definition: cvss.c:115
set_impact_from_str
static int set_impact_from_str(const char *value, enum base_metrics metric, struct cvss *cvss)
Set impact score from string representation.
Definition: cvss.c:261