]> sourceware.org Git - lvm2.git/commitdiff
toollib: fix segfault if using -S|--select with log/report_command_log=1 setting
authorPeter Rajnoha <prajnoha@redhat.com>
Tue, 7 Mar 2023 13:45:06 +0000 (14:45 +0100)
committerPeter Rajnoha <prajnoha@redhat.com>
Tue, 7 Mar 2023 14:29:54 +0000 (15:29 +0100)
When we are using -S|--select for non-reporting tools while using command log
reporting (log/report_command_log=1 setting), we need to create an internal
processing handle to handle the selection itself. In this case, the internal
processing handle to execute the selection (to process the -S|--select) has
a parent handle (that is processing the actual non-reporting command).

When this parent handle exists, we can't destroy the command log report
in destroy_processing_handle as there's still the parent processing to
finish. The parent processing may still generate logs which need to be
reported in the command log report. If the command log report was
destroyed prematurely together with destroying the internal processing
handle for -S|--select, then any subsequent log request from processing
the actual command (and hence an attermpt to access the command log report)
ended up with a segfault.

See also: https://bugzilla.redhat.com/show_bug.cgi?id=2175220

WHATS_NEW
tools/toollib.c

index 8523b5eb7dc8bf123269c63226891d79deac5926..7c979d69c62c562b182f626e2072eccd9ad6bb6d 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 version 2.03.20 - 
 ====================================
+  Fix segfault if using -S|--select with log/report_command_log=1 setting.
   Configure now fails when requested lvmlockd dependencies are missing.
   Add some configure Gentoo enhancements for static builds.
 
index 194088ea6a4e50686e19d49e752232bd767004b0..43e628abf7a0caed0b243fe99e72e1e02901a19f 100644 (file)
@@ -2050,7 +2050,20 @@ void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle
 
                log_restore_report_state(cmd->cmd_report.saved_log_report_state);
 
-               if (!cmd->is_interactive) {
+               /*
+                * Do not destroy current cmd->report_group and cmd->log_rh
+                * (the log report) yet if we're running interactively
+                * (== running in lvm shell) or if there's a parent handle
+                * (== we're executing nested processing, like it is when
+                * doing selection for parent's process_each_* processing).
+                *
+                * In both cases, there's still possible further processing
+                * to do outside the processing covered by the handle we are
+                * destroying here and for which we may still need to access
+                * the log report to cover the rest of the processing.
+                *
+                */
+               if (!cmd->is_interactive && !handle->parent) {
                        if (!dm_report_group_destroy(cmd->cmd_report.report_group))
                                stack;
                        cmd->cmd_report.report_group = NULL;
This page took 0.049753 seconds and 5 git commands to generate.