Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get vector #568

Merged
merged 3 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
Reintroduction after Rebase
[#538](https://github.com/greenbone/gvm-libs/pull/538)
- Add function for mqtt init status [#567](https://github.com/greenbone/gvm-libs/pull/567)
- Add function to get the severity_vector, otherwise the cvss_base_vector. [#568](https://github.com/greenbone/gvm-libs/pull/568)

### Changed

Expand Down
30 changes: 30 additions & 0 deletions base/nvti.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,36 @@ nvti_severity_score (const nvti_t *n)
return score;
}

/**
* @brief Get the severity score
*
* Extended severity was introduced but still not all
* vts are using it. Therefore it must be check if
ArnoStiefvater marked this conversation as resolved.
Show resolved Hide resolved
* we can calculate the score from the severity_vector tag
* or we have to calculate it from the deprecated
ArnoStiefvater marked this conversation as resolved.
Show resolved Hide resolved
* cvss_base_vector tag.
*
* @param n The NVT Info structure.
*
* @return The severity_vector if present or cvss_base_vector otherwise.
* NULL indicates an error. Must be free()'d by the caller.
*/
gchar *
nvti_severity_vector_from_tag (const nvti_t *n)
{
gchar *vector;

/* Currently, only one severity_vector can be stored as tag.
* Therfore we just check this one. */
vector = nvti_get_tag (n, "severity_vector");
if (vector)
return vector;

vector = nvti_get_tag (n, "cvss_base_vector");

return vector;
}

/**
* @brief Get the solution.
*
Expand Down
2 changes: 2 additions & 0 deletions base/nvti.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ vtseverity_t *
nvti_vtseverity (const nvti_t *, guint);
double
nvti_severity_score (const nvti_t *);
gchar *
nvti_severity_vector_from_tag (const nvti_t *);

nvti_t *
nvti_new (void);
Expand Down
47 changes: 47 additions & 0 deletions base/nvti_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,48 @@ Ensure (nvti, nvtis_add_does_not_use_oid_as_key)
assert_that (nvtis_lookup (nvtis, "2"), is_null);
}

/* nvti severity vector */

Ensure (nvti, nvti_get_severity_vector_both)
{
nvti_t *nvti;

nvti = nvti_new ();
nvti_set_tag (nvti, "cvss_base_vector=DEF");
nvti_set_tag (nvti, "severity_vector=ABC");

assert_that (nvti_severity_vector_from_tag (nvti),
is_equal_to_string ("ABC"));

nvti_free (nvti);
}

Ensure (nvti, nvti_get_severity_vector_no_cvss_base)
{
nvti_t *nvti;

nvti = nvti_new ();
nvti_set_tag (nvti, "severity_vector=ABC");

assert_that (nvti_severity_vector_from_tag (nvti),
is_equal_to_string ("ABC"));

nvti_free (nvti);
}

Ensure (nvti, nvti_get_severity_vector_no_severity_vector)
{
nvti_t *nvti;

nvti = nvti_new ();
nvti_set_tag (nvti, "cvss_base_vector=DEF");

assert_that (nvti_severity_vector_from_tag (nvti),
is_equal_to_string ("DEF"));

nvti_free (nvti);
}

/* Test suite. */

int
Expand All @@ -163,6 +205,11 @@ main (int argc, char **argv)

add_test_with_context (suite, nvti, nvtis_add_does_not_use_oid_as_key);

add_test_with_context (suite, nvti, nvti_get_severity_vector_both);
add_test_with_context (suite, nvti,
nvti_get_severity_vector_no_severity_vector);
add_test_with_context (suite, nvti, nvti_get_severity_vector_no_cvss_base);

if (argc > 1)
return run_single_test (suite, argv[1], create_text_reporter ());

Expand Down