From 91aebaed31a8d2898647cbdc5129d50ac1e25ee2 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 9 Aug 2023 15:07:18 +0200 Subject: [PATCH] Fix: Handle missing report getting task severity The task_severity_double function now no longer tries to get the severity from an undefined report if no report matches the criteria. Instead it passes the report row id 0 to report_severity, which will always return SEVERITY_MISSING in this case. This fixes the check for the "Severity changed" alert condition not working correctly if the task has no second report for comparison. --- src/manage_sql.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index d7f220061..d03bfbd4c 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -18861,13 +18861,12 @@ task_severity_double (task_t task, int overrides, int min_qod, int offset) || task_target (task) == 0 /* Container task. */) return SEVERITY_MISSING; - sql_int64 (&report, - "SELECT id FROM reports" - " WHERE reports.task = %llu" - " AND reports.scan_run_status = %u" - " ORDER BY reports.creation_time DESC" - " LIMIT 1 OFFSET %d", - task, TASK_STATUS_DONE, offset); + report = sql_int64_0 ("SELECT id FROM reports" + " WHERE reports.task = %llu" + " AND reports.scan_run_status = %u" + " ORDER BY reports.creation_time DESC" + " LIMIT 1 OFFSET %d", + task, TASK_STATUS_DONE, offset); return report_severity (report, overrides, min_qod); } @@ -24694,6 +24693,9 @@ report_severity (report_t report, int overrides, int min_qod) double severity; iterator_t iterator; + if (report == 0) + return SEVERITY_MISSING; + init_iterator (&iterator, "SELECT max(severity)" " FROM report_counts"