From 21c3a7c8d7d46f9af9a08ff44299cd22cc8cf9cb Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Wed, 18 Feb 2026 11:21:17 +0200 Subject: [PATCH] Change: move filtered counts into print_report_xml_start context This is a very simple first step, to keep the patch easy to understand. It just moves the f_host_* variables from the body of the function to the ctx struct. The NULL inits are redundant but I've kept them in for now, to minimize changes. --- src/manage_sql.c | 201 +++++++++++++++++++++++++---------------------- 1 file changed, 105 insertions(+), 96 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index cb27da8ef..44e961c39 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -16619,6 +16619,19 @@ struct print_report_context int warnings; ///< Number of warnings. int false_positives; ///< Number of false positives. int total_result_count; ///< Total number of results. + // Filtered counts. + GHashTable *f_host_false_positives; ///< False positives per host. + GHashTable *f_host_holes; ///< Holes per host. + GHashTable *f_host_infos; ///< Infos per host. + GHashTable *f_host_logs; ///< Logs per hosts. + GHashTable *f_host_ports; ///< Ports per host. + GHashTable *f_host_warnings; ///< Warnings per hosts. + // Filtered counts: audit. + GHashTable *f_host_criticals; ///< Criticals per host. + GHashTable *f_host_compliant; ///< Compliants per host. + GHashTable *f_host_incomplete; ///< Incompletes per host. + GHashTable *f_host_notcompliant; ///< Notcompliants per host. + GHashTable *f_host_undefined; ///< Undefineds per host. }; /** @@ -16777,12 +16790,6 @@ print_report_xml_start (report_t report, report_t delta, task_t task, int search_phrase_exact, apply_overrides; double severity, f_severity; GString *filters_buffer, *filters_extra_buffer, *host_summary_buffer; - GHashTable *f_host_ports; - GHashTable *f_host_holes, *f_host_warnings, *f_host_infos; - GHashTable *f_host_logs, *f_host_false_positives; - GHashTable *f_host_compliant, *f_host_notcompliant; - GHashTable *f_host_incomplete, *f_host_undefined; - GHashTable *f_host_criticals = NULL; task_status_t run_status; int f_compliance_yes, f_compliance_no; int f_compliance_incomplete, f_compliance_undefined; @@ -16801,16 +16808,17 @@ print_report_xml_start (report_t report, report_t delta, task_t task, orig_f_false_positives = orig_f_warnings = orig_f_logs = orig_f_infos = 0; orig_f_holes = orig_f_criticals = 0; host_summary_buffer = NULL; - f_host_ports = NULL; - f_host_holes = NULL; - f_host_warnings = NULL; - f_host_infos = NULL; - f_host_logs = NULL; - f_host_false_positives = NULL; - f_host_compliant = NULL; - f_host_notcompliant = NULL; - f_host_incomplete = NULL; - f_host_undefined = NULL; + ctx.f_host_criticals = NULL; + ctx.f_host_ports = NULL; + ctx.f_host_holes = NULL; + ctx.f_host_warnings = NULL; + ctx.f_host_infos = NULL; + ctx.f_host_logs = NULL; + ctx.f_host_false_positives = NULL; + ctx.f_host_compliant = NULL; + ctx.f_host_notcompliant = NULL; + ctx.f_host_incomplete = NULL; + ctx.f_host_undefined = NULL; ctx.delta = delta; ctx.get = get; @@ -17348,18 +17356,19 @@ print_report_xml_start (report_t report, report_t delta, task_t task, /* Port summary. */ - f_host_ports = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); + ctx.f_host_ports = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); reuse_result_iterator = 0; if (get->details && (delta == 0)) { reuse_result_iterator = 1; if (print_report_port_xml (report, out, get, first_result, max_results, - sort_order, sort_field, f_host_ports, &results)) + sort_order, sort_field, ctx.f_host_ports, + &results)) { g_free (term); - g_hash_table_destroy (f_host_ports); + g_hash_table_destroy (ctx.f_host_ports); goto fail; } } @@ -17430,7 +17439,7 @@ print_report_xml_start (report_t report, report_t delta, task_t task, get, term, sort_field)) { g_free (term); - g_hash_table_destroy (f_host_ports); + g_hash_table_destroy (ctx.f_host_ports); goto fail; } } @@ -17445,7 +17454,7 @@ print_report_xml_start (report_t report, report_t delta, task_t task, res = init_result_get_iterator (&results, get, report, NULL, NULL); if (res) { - g_hash_table_destroy (f_host_ports); + g_hash_table_destroy (ctx.f_host_ports); goto fail; } } @@ -17469,29 +17478,30 @@ print_report_xml_start (report_t report, report_t delta, task_t task, if (strcmp (ctx.tsk_usage_type, "audit") == 0) { - f_host_compliant = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - f_host_notcompliant = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - f_host_incomplete = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - f_host_undefined = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); + ctx.f_host_compliant = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + ctx.f_host_notcompliant = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + ctx.f_host_incomplete = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + ctx.f_host_undefined = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); } else { - f_host_criticals = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - f_host_holes = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - f_host_warnings = g_hash_table_new_full (g_str_hash, g_str_equal, + ctx.f_host_criticals = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + ctx.f_host_holes = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + ctx.f_host_warnings = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + ctx.f_host_infos = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + ctx.f_host_logs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - f_host_infos = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - f_host_logs = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - f_host_false_positives = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); + ctx.f_host_false_positives = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, NULL); } if (delta && get->details) @@ -17561,25 +17571,25 @@ print_report_xml_start (report_t report, report_t delta, task_t task, if (strcasecmp (compliance, "yes") == 0) { - f_host_result_counts = f_host_compliant; + f_host_result_counts = ctx.f_host_compliant; if (ctx.count_filtered) f_compliance_yes++; } else if (strcasecmp (compliance, "no") == 0) { - f_host_result_counts = f_host_notcompliant; + f_host_result_counts = ctx.f_host_notcompliant; if (ctx.count_filtered) f_compliance_no++; } else if (strcasecmp (compliance, "incomplete") == 0) { - f_host_result_counts = f_host_incomplete; + f_host_result_counts = ctx.f_host_incomplete; if (ctx.count_filtered) f_compliance_incomplete++; } else if (strcasecmp (compliance, "undefined") == 0) { - f_host_result_counts = f_host_undefined; + f_host_result_counts = ctx.f_host_undefined; if (ctx.count_filtered) f_compliance_undefined++; } @@ -17612,37 +17622,37 @@ print_report_xml_start (report_t report, report_t delta, task_t task, if (strcasecmp (level, "log") == 0) { - f_host_result_counts = f_host_logs; + f_host_result_counts = ctx.f_host_logs; if (ctx.count_filtered) f_logs++; } else if (strcasecmp (level, "critical") == 0) { - f_host_result_counts = f_host_criticals; + f_host_result_counts = ctx.f_host_criticals; if (ctx.count_filtered) f_criticals++; } else if (strcasecmp (level, "high") == 0) { - f_host_result_counts = f_host_holes; + f_host_result_counts = ctx.f_host_holes; if (ctx.count_filtered) f_holes++; } else if (strcasecmp (level, "medium") == 0) { - f_host_result_counts = f_host_warnings; + f_host_result_counts = ctx.f_host_warnings; if (ctx.count_filtered) f_warnings++; } else if (strcasecmp (level, "low") == 0) { - f_host_result_counts = f_host_infos; + f_host_result_counts = ctx.f_host_infos; if (ctx.count_filtered) f_infos++; } else if (strcasecmp (level, "false positive") == 0) { - f_host_result_counts = f_host_false_positives; + f_host_result_counts = ctx.f_host_false_positives; if (ctx.count_filtered) f_false_positives++; } @@ -17846,17 +17856,17 @@ print_report_xml_start (report_t report, report_t delta, task_t task, ctx.tsk_usage_type, lean, host_summary_buffer, - f_host_ports, - f_host_criticals, - f_host_holes, - f_host_warnings, - f_host_infos, - f_host_logs, - f_host_false_positives, - f_host_compliant, - f_host_notcompliant, - f_host_incomplete, - f_host_undefined)) + ctx.f_host_ports, + ctx.f_host_criticals, + ctx.f_host_holes, + ctx.f_host_warnings, + ctx.f_host_infos, + ctx.f_host_logs, + ctx.f_host_false_positives, + ctx.f_host_compliant, + ctx.f_host_notcompliant, + ctx.f_host_incomplete, + ctx.f_host_undefined)) { goto failed_print_report_host; } @@ -17876,39 +17886,38 @@ print_report_xml_start (report_t report, report_t delta, task_t task, ctx.tsk_usage_type, lean, host_summary_buffer, - f_host_ports, - f_host_criticals, - f_host_holes, - f_host_warnings, - f_host_infos, - f_host_logs, - f_host_false_positives, - f_host_compliant, - f_host_notcompliant, - f_host_incomplete, - f_host_undefined)) - + ctx.f_host_ports, + ctx.f_host_criticals, + ctx.f_host_holes, + ctx.f_host_warnings, + ctx.f_host_infos, + ctx.f_host_logs, + ctx.f_host_false_positives, + ctx.f_host_compliant, + ctx.f_host_notcompliant, + ctx.f_host_incomplete, + ctx.f_host_undefined)) goto failed_print_report_host; } cleanup_iterator (&hosts); } if (strcmp (ctx.tsk_usage_type, "audit") == 0) { - g_hash_table_destroy (f_host_compliant); - g_hash_table_destroy (f_host_notcompliant); - g_hash_table_destroy (f_host_incomplete); - g_hash_table_destroy (f_host_undefined); + g_hash_table_destroy (ctx.f_host_compliant); + g_hash_table_destroy (ctx.f_host_notcompliant); + g_hash_table_destroy (ctx.f_host_incomplete); + g_hash_table_destroy (ctx.f_host_undefined); } else { - g_hash_table_destroy (f_host_criticals); - g_hash_table_destroy (f_host_holes); - g_hash_table_destroy (f_host_warnings); - g_hash_table_destroy (f_host_infos); - g_hash_table_destroy (f_host_logs); - g_hash_table_destroy (f_host_false_positives); + g_hash_table_destroy (ctx.f_host_criticals); + g_hash_table_destroy (ctx.f_host_holes); + g_hash_table_destroy (ctx.f_host_warnings); + g_hash_table_destroy (ctx.f_host_infos); + g_hash_table_destroy (ctx.f_host_logs); + g_hash_table_destroy (ctx.f_host_false_positives); } - g_hash_table_destroy (f_host_ports); + g_hash_table_destroy (ctx.f_host_ports); /* Print TLS certificates */ @@ -18011,24 +18020,24 @@ print_report_xml_start (report_t report, report_t delta, task_t task, failed_print_report_host: if (host_summary_buffer) g_string_free (host_summary_buffer, TRUE); - g_hash_table_destroy (f_host_ports); + g_hash_table_destroy (ctx.f_host_ports); g_free (compliance_levels); if (strcmp (ctx.tsk_usage_type, "audit") == 0) { - g_hash_table_destroy (f_host_compliant); - g_hash_table_destroy (f_host_notcompliant); - g_hash_table_destroy (f_host_incomplete); - g_hash_table_destroy (f_host_undefined); + g_hash_table_destroy (ctx.f_host_compliant); + g_hash_table_destroy (ctx.f_host_notcompliant); + g_hash_table_destroy (ctx.f_host_incomplete); + g_hash_table_destroy (ctx.f_host_undefined); } else { - g_hash_table_destroy (f_host_criticals); - g_hash_table_destroy (f_host_holes); - g_hash_table_destroy (f_host_warnings); - g_hash_table_destroy (f_host_infos); - g_hash_table_destroy (f_host_logs); - g_hash_table_destroy (f_host_false_positives); + g_hash_table_destroy (ctx.f_host_criticals); + g_hash_table_destroy (ctx.f_host_holes); + g_hash_table_destroy (ctx.f_host_warnings); + g_hash_table_destroy (ctx.f_host_infos); + g_hash_table_destroy (ctx.f_host_logs); + g_hash_table_destroy (ctx.f_host_false_positives); } fail: tz_revert (ctx.zone, ctx.tz, ctx.old_tz_override);