Skip to content

Commit

Permalink
Fix: task status overwrite when a task is stopped and quickly restart…
Browse files Browse the repository at this point in the history
…ed (not resumed) #1779

This is a bug-fix. It addresses SC-505.
  • Loading branch information
jhelmold authored Feb 21, 2022
2 parents a39b162 + a9d33c6 commit a34fa70
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,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 connection error, -2 on fail to find scan,
* 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 @@ -1644,9 +1645,13 @@ get_osp_scan_report (const char *scan_id, const char *host, int port,
pop_results, &error);
if (progress > 100 || progress < 0)
{
if (g_strrstr (error, "Failed to find scan") != NULL)
progress = -2; // Scan already deleted
else
progress = -1; // connection error. Should retry.
g_warning ("OSP get_scan %s: %s", scan_id, error);
g_free (error);
progress = -1;

}

osp_connection_close (connection);
Expand Down Expand Up @@ -1703,7 +1708,7 @@ get_osp_scan_status (const char *scan_id, const char *host, int port,
* @param[in] scan_id The UUID of the scan on the scanner.
*
* @return 0 if success, -1 if error, -2 if scan was stopped,
* -3 if the scan was interrupted.
* -3 if the scan was interrupted, -4 already stopped.
*/
static int
handle_osp_scan (task_t task, report_t report, const char *scan_id)
Expand Down Expand Up @@ -1735,7 +1740,7 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
if (run_status == TASK_STATUS_STOPPED
|| run_status == TASK_STATUS_STOP_REQUESTED)
{
rc = -2;
rc = -4;
break;
}

Expand All @@ -1745,14 +1750,19 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)

if (progress < 0 || progress > 100)
{
if (retry > 0)
if (retry > 0 && progress == -1)
{
retry--;
g_warning ("Connection lost with the scanner at %s. "
"Trying again in 1 second.", host);
gvm_sleep (1);
continue;
}
else if (progress == -2)
{
rc = -2;
break;
}
result_t result = make_osp_result
(task, "", "", "",
threat_message_type ("Error"),
Expand All @@ -1772,15 +1782,19 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
key_priv, 1, 1, &report_xml);
if (progress < 0 || progress > 100)
{
if (retry > 0)
if (retry > 0 && progress == -1)
{
retry--;
g_warning ("Connection lost with the scanner at %s. "
"Trying again in 1 second.", host);
gvm_sleep (1);
continue;
}

else if (progress == -2)
{
rc = -2;
break;
}
g_free (report_xml);
result_t result = make_osp_result
(task, "", "", "",
Expand Down

0 comments on commit a34fa70

Please sign in to comment.