File bsc#1198409-0002-Fix-tools-prevent-possible-crm_resource-segfaults-if.patch of Package pacemaker.26927

From a1c3b2ea6c54ac18635fa5c5d5e5d95f580bb067 Mon Sep 17 00:00:00 2001
From: "Gao,Yan" <ygao@suse.com>
Date: Thu, 14 Apr 2022 12:23:20 +0200
Subject: [PATCH 2/3] Fix: tools: prevent possible crm_resource segfaults if
 multiple commands are specified

The argument callbacks assume they have the originally initialized
options and update the values accordingly.

While we still accept multiple commands for backward compatibility, the
relevant options should be reset whenever an existing command is
overridden. Otherwise the options would result into havoc and possibly
cause segfaults of problematically composed commands such as
`crm_resource -l -a`.
---
 tools/crm_resource.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Index: pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_resource.c
===================================================================
--- pacemaker-2.0.4+20200616.2deceaa3a.orig/tools/crm_resource.c
+++ pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_resource.c
@@ -25,7 +25,18 @@
 #include <libgen.h>
 #include <time.h>
 
-#define SET_COMMAND(cmd) do { rsc_cmd = (cmd); } while (0)
+#define reset_options() do {                                                \
+        require_crmd = FALSE;                                               \
+        require_dataset = TRUE;                                             \
+        require_resource = TRUE;                                            \
+        find_flags = 0;                                                     \
+    } while (0)
+
+#define SET_COMMAND(cmd) do {                                               \
+        reset_options();                                                    \
+        rsc_long_cmd = NULL;                                                \
+        rsc_cmd = (cmd);                                                    \
+    } while (0)
 
 bool BE_QUIET = FALSE;
 bool scope_master = FALSE;
openSUSE Build Service is sponsored by