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

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.5+20201202.ba59be712/tools/crm_resource.c
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/tools/crm_resource.c
+++ pacemaker-2.0.5+20201202.ba59be712/tools/crm_resource.c
@@ -117,7 +117,12 @@ struct {
         options.rsc_cmd = (cmd);                                            \
     } while (0)
 #else
-#define SET_COMMAND(cmd) do { options.rsc_cmd = (cmd); } while (0)
+#define SET_COMMAND(cmd) do {                                               \
+        if (options.rsc_cmd != cmd_none) {                                  \
+            reset_options();                                                \
+        }                                                                   \
+        options.rsc_cmd = (cmd);                                            \
+    } while (0)
 #endif
 
 gboolean agent_provider_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error);
@@ -587,6 +592,17 @@ static GOptionEntry addl_entries[] = {
     { NULL }
 };
 
+static void
+reset_options(void) {
+    options.require_crmd = FALSE;
+
+    options.require_cib = TRUE,
+    options.require_dataset = TRUE,
+    options.require_resource = TRUE,
+
+    options.find_flags = 0;
+}
+
 gboolean
 agent_provider_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error) {
     options.validate_cmdline = TRUE;
openSUSE Build Service is sponsored by