diff --git a/src/manage_pg.c b/src/manage_pg.c index 8bcad5351..b39368f7f 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -870,6 +870,19 @@ manage_create_sql_functions () "$$ LANGUAGE plpgsql" " IMMUTABLE;"); + sql ("CREATE OR REPLACE FUNCTION normalize_port (" + " port text)" + "RETURNS text AS $$ " + "BEGIN" + " CASE" + " WHEN port = 'package'" + " THEN RETURN 'general/tcp';" + " ELSE RETURN port;" + " END CASE;" + "END;" + "$$ LANGUAGE plpgsql" + " IMMUTABLE;"); + /* Functions in SQL. */ if (sql_int ("SELECT (EXISTS (SELECT * FROM information_schema.tables" diff --git a/src/manage_sql.c b/src/manage_sql.c index 324ebc143..9c61ab50e 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -27517,20 +27517,22 @@ init_v2_delta_iterator (report_t report, iterator_t *results, report_t delta, " severity, nvt, results.qod, results.uuid, hostname," " path, r1_lateral.new_severity as new_severity " " FROM results " - " JOIN (SELECT cvss_base, oid AS nvts_oid from nvts) AS nvts_cols" + " LEFT JOIN (SELECT cvss_base, oid AS nvts_oid from nvts)" + " AS nvts_cols" " ON nvts_cols.nvts_oid = results.nvt" " %s, LATERAL %s AS r1_lateral" " WHERE report = %llu)" " AS r1" " FULL OUTER JOIN (SELECT results.*, r2_lateral.new_severity AS new_severity" " FROM results" - " JOIN (SELECT cvss_base, oid AS nvts_oid from nvts) AS nvts_cols" + " LEFT JOIN (SELECT cvss_base, oid AS nvts_oid from nvts)" + " AS nvts_cols" " ON nvts_cols.nvts_oid = results.nvt" " %s, LATERAL %s AS r2_lateral" " WHERE report = %llu)" " AS r2" " ON r1.host = r2.host" - " AND r1.port = r2.port" + " AND normalize_port(r1.port) = normalize_port(r2.port)" " AND r1.nvt = r2.nvt " " AND (r1.new_severity = 0) = (r2.new_severity = 0)" " )",