File pacemaker#3574-0001-Fix-tools-crm_node-i-must-initialize-nodeid-before-p.patch of Package pacemaker.36799

From 22e093a5bff608c86d0ea68588078ca747a6d945 Mon Sep 17 00:00:00 2001
From: Reid Wahl <nrwahl@protonmail.com>
Date: Thu, 11 Jul 2024 12:29:34 -0700
Subject: [PATCH] Fix: tools: crm_node -i must initialize nodeid before passing
 pointer

This is a regression introduced in 2.1.7 via a27f099.

Currently, crm_node -i passes a pointer to the uninitialized uint32_t
nodeid variable, to pcmk__query_node_info(). Since the pointer is
non-NULL, pcmk__query_node_info() dereferences it. Whatever garbage
value resides there gets passed as the ID to query.

The controller parses the node ID from the request as an int. If the
garbage value is greater than INT_MAX, it overflows to a negative int
value, and the controller (in handle_node_info_request()) defaults it to
0. In that case, there's no problem: we search for the local node name
instead of the garbage node ID.

If the garbage value is less than or equal to INT_MAX, we search for it
directly. We won't find a matching node unless one happens to exist with
that garbage node ID. In the case of no match, crm_node -i outputs "Node
is not known to cluster" instead of the local node's cluster-layer ID.

Thanks to Artur Novik for the report:
https://lists.clusterlabs.org/pipermail/users/2024-July/036270.html

Fixes T847

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
---
 lib/pacemaker/pcmk_cluster_queries.c | 22 +++++++++++-----------
 tools/crm_node.c                     |  2 +-
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/pacemaker/pcmk_cluster_queries.c b/lib/pacemaker/pcmk_cluster_queries.c
index 3229fae3ef..8404584580 100644
--- a/lib/pacemaker/pcmk_cluster_queries.c
+++ b/lib/pacemaker/pcmk_cluster_queries.c
@@ -586,25 +586,25 @@ pcmk_designated_controller(xmlNodePtr *xml, unsigned int message_timeout_ms)
  *        the controller
  *
  * \param[in,out] out                 Output object
- * \param[in,out] node_id             ID of node whose name to get. If \p NULL
- *                                    or 0, get the local node name. If not
- *                                    \p NULL, store the true node ID here on
+ * \param[in,out] node_id             ID of node whose info to get. If \p NULL
+ *                                    or 0, get the local node's info. If not
+ *                                    \c NULL, store the true node ID here on
  *                                    success.
- * \param[out]    node_name           If not \p NULL, where to store the node
+ * \param[out]    node_name           If not \c NULL, where to store the node
  *                                    name
- * \param[out]    uuid                If not \p NULL, where to store the node
+ * \param[out]    uuid                If not \c NULL, where to store the node
  *                                    UUID
- * \param[out]    state               If not \p NULL, where to store the
+ * \param[out]    state               If not \c NULL, where to store the
  *                                    membership state
- * \param[out]    is_remote           If not \p NULL, where to store whether the
+ * \param[out]    is_remote           If not \c NULL, where to store whether the
  *                                    node is a Pacemaker Remote node
- * \param[out]    have_quorum         If not \p NULL, where to store whether the
+ * \param[out]    have_quorum         If not \c NULL, where to store whether the
  *                                    node has quorum
  * \param[in]     show_output         Whether to show the node info
  * \param[in]     message_timeout_ms  How long to wait for a reply from the
- *                                    \p pacemaker-controld API. If 0,
- *                                    \p pcmk_ipc_dispatch_sync will be used.
- *                                    Otherwise, \p pcmk_ipc_dispatch_poll will
+ *                                    \c pacemaker-controld API. If 0,
+ *                                    \c pcmk_ipc_dispatch_sync will be used.
+ *                                    Otherwise, \c pcmk_ipc_dispatch_poll will
  *                                    be used.
  *
  * \return Standard Pacemaker return code
diff --git a/tools/crm_node.c b/tools/crm_node.c
index d4153605a6..8aa8d3d29c 100644
--- a/tools/crm_node.c
+++ b/tools/crm_node.c
@@ -434,7 +434,7 @@ run_controller_mainloop(void)
 static void
 print_node_id(void)
 {
-    uint32_t nodeid;
+    uint32_t nodeid = 0;
     int rc = pcmk__query_node_info(out, &nodeid, NULL, NULL, NULL, NULL, NULL,
                                    false, 0);
 
-- 
2.35.3

openSUSE Build Service is sponsored by