Skip to content

Commit

Permalink
Add original severity and level to delta iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h-abdelsalam committed Oct 19, 2023
1 parent f8825bc commit b7554e2
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 30 deletions.
5 changes: 2 additions & 3 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -9233,9 +9233,8 @@ buffer_results_xml (GString *buffer, iterator_t *results, task_t task,
descr = result_iterator_delta_description (results);
severity = result_iterator_delta_severity (results);
severity_double = result_iterator_delta_severity_double (results);
//TODO use original severity
original_severity = result_iterator_delta_severity (results);
original_level = result_iterator_delta_level (results);
original_severity = result_iterator_delta_original_severity (results);
original_level = result_iterator_delta_original_level (results);
qod = result_iterator_delta_qod (results);
qod_type = result_iterator_delta_qod_type (results);
result = result_iterator_delta_result (results);
Expand Down
15 changes: 12 additions & 3 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,18 @@ result_iterator_delta_severity (iterator_t*);
double
result_iterator_delta_severity_double (iterator_t*);

const char*
result_iterator_delta_level (iterator_t*);

const char *
result_iterator_delta_original_severity (iterator_t*);

double
result_iterator_delta_original_severity_double (iterator_t*);

const char*
result_iterator_delta_original_level (iterator_t*);

const char *
result_iterator_delta_qod (iterator_t*);

Expand Down Expand Up @@ -1569,9 +1581,6 @@ result_iterator_delta_nvt_version (iterator_t*);
result_t
result_iterator_delta_result (iterator_t*);

const char *
result_iterator_delta_level (iterator_t*);

int
result_iterator_delta_may_have_notes (iterator_t*);

Expand Down
119 changes: 95 additions & 24 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -22272,9 +22272,6 @@ where_qod (int min_qod)
KEYWORD_TYPE_STRING }, \
{ "delta_nvt_version", NULL, KEYWORD_TYPE_STRING }, \
{ "result2_id", NULL, KEYWORD_TYPE_INTEGER }, \
{ "severity_to_type (results.severity)", \
"original_type", \
KEYWORD_TYPE_STRING }, \
{ "(SELECT CASE" \
" WHEN EXISTS (SELECT * FROM notes" \
" WHERE (result = result2_id" \
Expand All @@ -22298,7 +22295,8 @@ where_qod (int min_qod)
{ TICKET_SQL_RESULT_MAY_HAVE_TICKETS("result2_id"), \
NULL, \
KEYWORD_TYPE_INTEGER }, \
{ "delta_hostname", NULL, KEYWORD_TYPE_STRING },
{ "delta_hostname", NULL, KEYWORD_TYPE_STRING }, \
{ "delta_new_severity", NULL, KEYWORD_TYPE_DOUBLE },

/**
* @brief Delta result iterator columns.
Expand Down Expand Up @@ -23565,7 +23563,7 @@ result_iterator_delta_description (iterator_t* iterator)
* @return delta severity if any, else NULL.
*/
const char *
result_iterator_delta_severity (iterator_t* iterator)
result_iterator_delta_original_severity (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_string (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 2);
Expand All @@ -23579,12 +23577,40 @@ result_iterator_delta_severity (iterator_t* iterator)
* @return delta severity (double) if any, else 0.
*/
double
result_iterator_delta_severity_double (iterator_t* iterator)
result_iterator_delta_original_severity_double (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_double (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 2);
}

/**
* @brief Get the severity/threat level from a delta result iterator.
*
* This is the the original level.
*
* @param[in] iterator Iterator.
*
* @return The threat level of the delta result. Caller must only use before
* calling cleanup_iterator.
*/
const char*
result_iterator_delta_original_level (iterator_t* iterator)
{
double severity;
const char* ret;

if (iterator->done)
return "";

/* new_severity */
if (iterator_null (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 2))
return "";

severity = iterator_double (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 2);

ret = severity_to_level (severity, 0);
return ret ? ret : "";
}

/**
* @brief Get delta qod from a result iterator.
Expand Down Expand Up @@ -23755,20 +23781,6 @@ result_iterator_delta_result (iterator_t* iterator)
return iterator_int64 (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 14);
}

/**
* @brief Get delta level from a result iterator.
*
* @param[in] iterator Iterator.
*
* @return delta level if any, else NULL.
*/
const char *
result_iterator_delta_level (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_string (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 15);
}

/**
* @brief Get whether there are notes for the delta result from the iterator.
*
Expand All @@ -23780,7 +23792,7 @@ int
result_iterator_delta_may_have_notes (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_int (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 16);
return iterator_int (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 15);
}

/**
Expand All @@ -23794,7 +23806,7 @@ int
result_iterator_delta_may_have_overrides (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_int (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 17);
return iterator_int (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 16);
}

/**
Expand All @@ -23808,7 +23820,7 @@ int
result_iterator_delta_may_have_tickets (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_int (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 18);
return iterator_int (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 17);
}

/**
Expand All @@ -23820,11 +23832,69 @@ result_iterator_delta_may_have_tickets (iterator_t* iterator)
*/
const char *
result_iterator_delta_hostname (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_string (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 18);
}


/**
* @brief Get delta severity from a result iterator.
*
* @param[in] iterator Iterator.
*
* @return delta severity if any, else NULL.
*/
const char *
result_iterator_delta_severity (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_string (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 19);
}

/**
* @brief Get delta severity (double) from a result iterator.
*
* @param[in] iterator Iterator.
*
* @return delta severity (double) if any, else 0.
*/
double
result_iterator_delta_severity_double (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_double (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 19);
}

/**
* @brief Get the severity/threat level from a delta result iterator.
*
* This is the the overridden level.
*
* @param[in] iterator Iterator.
*
* @return The threat level of the delta result. Caller must only use before
* calling cleanup_iterator.
*/
const char*
result_iterator_delta_level (iterator_t* iterator)
{
double severity;
const char* ret;

if (iterator->done)
return "";

/* new_severity */
if (iterator_null (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 19))
return "";

severity = iterator_double (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 19);

ret = severity_to_level (severity, 0);
return ret ? ret : "";
}


/**
* @brief Append an NVT's references to an XML string buffer.
Expand Down Expand Up @@ -27429,7 +27499,8 @@ init_v2_delta_iterator (report_t report, iterator_t *results, report_t delta,
" r1.path,"
" r2.path) AS state,"
" r2.description AS delta_description,"
" r2.new_severity AS delta_severity,"
" r2.new_severity AS delta_new_severity,"
" r2.severity AS delta_severity,"
" r2.qod AS delta_qod,"
" r2.qod_type AS delta_qod_type,"
" r2.uuid AS delta_uuid,"
Expand Down

0 comments on commit b7554e2

Please sign in to comment.