Skip to content

Commit

Permalink
Add normalization for ports and fix the join for delta reports genera…
Browse files Browse the repository at this point in the history
…tion

- Treat "package" and "general/tcp" the same for delta comparison
- Ensure results are included in delta reports if nvts are missing
  • Loading branch information
a-h-abdelsalam committed Oct 19, 2023
1 parent b7554e2 commit b06952f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
" )",
Expand Down

0 comments on commit b06952f

Please sign in to comment.