From 367e303869c71502ae2e07fb49024e69bf1faa08 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 28 Aug 2025 10:18:00 +0200 Subject: [PATCH 1/3] Fix: Improve error handling in fork_scan_handler The fork_scan_handler function will now check the return values of the `pipe` and `write` calls, log warnings if there was an error and return / exit with a failure code. --- src/manage_scan_handler.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/manage_scan_handler.c b/src/manage_scan_handler.c index d3f24b8367..c9df0cd29f 100644 --- a/src/manage_scan_handler.c +++ b/src/manage_scan_handler.c @@ -195,8 +195,14 @@ fork_scan_handler (const char *report_id, report_t report, task_t task, pid_t child_pid; pid_t grandchild_pid; struct sigaction action; + int ret; - pipe (pipe_fds); + if (pipe (pipe_fds)) + { + g_warning ("%s: Failed to create pipe: %s", + __func__, strerror(errno)); + return -1; + } child_pid = fork(); (void) handle_scan_queue_entry; @@ -240,10 +246,20 @@ fork_scan_handler (const char *report_id, report_t report, task_t task, exit (EXIT_FAILURE); default: // Child on success - write (pipe_fds[1], &grandchild_pid, sizeof(grandchild_pid)); - close(pipe_fds[1]); // Close output side of pipe + ret = write (pipe_fds[1], + &grandchild_pid, + sizeof(grandchild_pid)); + if (ret) + { + g_warning ("%s: Failed to write PID to pipe: %s", + __func__, strerror(errno)); + } + close (pipe_fds[1]); // Close output side of pipe sql_close_fork (); - exit(EXIT_SUCCESS); + if (ret) + exit(EXIT_FAILURE); + else + exit(EXIT_SUCCESS); } } case -1: From af4ce3143878b86fab11f1bdac0f817a5409bbb7 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 28 Aug 2025 10:32:30 +0200 Subject: [PATCH 2/3] Fix: Init print_report_xml_start compliance counts The compliance counts (compliance_yes, compliance_no, compliance_incomplete and compliance_undefined) in the print_report_xml_start function are now initialized with 0. --- src/manage_sql.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index 9c72588c61..a32524d06e 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -20595,8 +20595,8 @@ print_report_xml_start (report_t report, report_t delta, task_t task, } /* Prepare result counts. */ - int compliance_yes, compliance_no; - int compliance_incomplete, compliance_undefined; + int compliance_yes = 0, compliance_no = 0; + int compliance_incomplete = 0, compliance_undefined = 0; int total_compliance_count = 0; if (strcmp (tsk_usage_type, "audit") == 0) From 071ee06b683522442374987767ec98b1f2c1616a Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 28 Aug 2025 10:42:10 +0200 Subject: [PATCH 3/3] Init host_summary_buffer in print_report_xml_start The host_summary_buffer variable in print_report_xml_start is initialized to NULL so it is not uninitialized in case of errors. --- src/manage_sql.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/manage_sql.c b/src/manage_sql.c index a32524d06e..340d8d9d71 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -19997,6 +19997,7 @@ print_report_xml_start (report_t report, report_t delta, task_t task, orig_filtered_result_count = 0; 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;