Skip to content

Commit

Permalink
Set the task as interrupted if the progress is -2
Browse files Browse the repository at this point in the history
Ospd sends -2 as scan progress value if the scanner was unexpectedly interrupted.
  • Loading branch information
jjnicola committed Jun 24, 2020
1 parent e388e7b commit e8e8661
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ truncate_text (gchar *string, size_t max_len, gboolean xml, const char *suffix)
// move the offset to the start of that entity.
ssize_t entity_start_offset = offset;

while (entity_start_offset >= 0
while (entity_start_offset >= 0
&& string[entity_start_offset] != '&')
{
entity_start_offset --;
Expand Down Expand Up @@ -3466,7 +3466,8 @@ delete_osp_scan (const char *report_id, const char *host, int port,
* @param[in] pop_results 1 to pop results, 0 to leave results intact.
* @param[out] report_xml Scan report.
*
* @return -1 on error, progress value between 0 and 100 on success.
* @return -1 on error, -2 if the scan was interrupted, progress value
* between 0 and 100 on success.
*/
static int
get_osp_scan_report (const char *scan_id, const char *host, int port,
Expand All @@ -3485,7 +3486,8 @@ get_osp_scan_report (const char *scan_id, const char *host, int port,
}
progress = osp_get_scan_pop (connection, scan_id, report_xml, details,
pop_results, &error);
if (progress > 100 || progress < 0)
/* Progress -2 is received when a scanner is interrupted. */
if ((progress > 100 || progress < 0) && progress != -2)
{
g_warning ("OSP get_scan %s: %s", scan_id, error);
g_free (error);
Expand Down Expand Up @@ -3545,7 +3547,8 @@ get_osp_scan_status (const char *scan_id, const char *host, int port,
* @param[in] report The report.
* @param[in] scan_id The UUID of the scan on the scanner.
*
* @return 0 if success, -1 if error, -2 if scan was stopped.
* @return 0 if success, -1 if error, -2 if scan was stopped,
* -3 if the scan was interrupted.
*/
static int
handle_osp_scan (task_t task, report_t report, const char *scan_id)
Expand Down Expand Up @@ -3580,7 +3583,7 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)

progress = get_osp_scan_report (scan_id, host, port, ca_pub, key_pub,
key_priv, 0, 0, &report_xml);
if (progress < 0 || progress > 100)
if ((progress < 0 || progress > 100) && progress != -2)
{
result_t result = make_osp_result
(task, "", "", "",
Expand All @@ -3593,12 +3596,25 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
rc = -1;
break;
}
else if (progress == -2)
{
result_t result = make_osp_result
(task, "", "", "",
threat_message_type ("Error"),
"Task interrupted unexpectedly", "", "",
QOD_DEFAULT);
report_add_result (report, result);
delete_osp_scan (scan_id, host, port, ca_pub, key_pub,
key_priv);
rc = -3;
break;
}
else
{
/* Get the full OSP report. */
progress = get_osp_scan_report (scan_id, host, port, ca_pub, key_pub,
key_priv, 1, 1, &report_xml);
if (progress < 0 || progress > 100)
if ((progress < 0 || progress > 100) && progress != -2)
{
result_t result = make_osp_result
(task, "", "", "",
Expand All @@ -3609,6 +3625,19 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
rc = -1;
break;
}
else if (progress == -2)
{
result_t result = make_osp_result
(task, "", "", "",
threat_message_type ("Error"),
"Task interrupted unexpectedly", "", "",
QOD_DEFAULT);
report_add_result (report, result);
delete_osp_scan (scan_id, host, port, ca_pub, key_pub,
key_priv);
rc = -3;
break;
}
else
{
set_report_slave_progress (report, progress);
Expand Down Expand Up @@ -4560,6 +4589,11 @@ fork_osp_scan_handler (task_t task, target_t target, int from,
set_task_run_status (task, TASK_STATUS_STOPPED);
set_report_scan_run_status (global_current_report, TASK_STATUS_STOPPED);
}
else if (rc == -3)
{
set_task_run_status (task, TASK_STATUS_INTERRUPTED);
set_report_scan_run_status (global_current_report, TASK_STATUS_INTERRUPTED);
}

set_task_end_time_epoch (task, time (NULL));
set_scan_end_time_epoch (global_current_report, time (NULL));
Expand Down

0 comments on commit e8e8661

Please sign in to comment.