File pacemaker#3379-0001-Low-tools-Fix-argument-validation-for-crm_attribute-.patch of Package pacemaker.36842
From 88d94635bc1d1387863d7454ec99c6de70abf439 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 29 Feb 2024 15:50:04 -0500
Subject: [PATCH] Low: tools: Fix argument validation for crm_attribute update.
Previously (perhaps as far back as when crm_attribute was introduced) we
haven't done any validation on whether an attribute name was given along
with the -v option specifying the new attribute value. Instead we just
asserted.
Instead, check that a name or pattern was given and if not, display an
error message. The other two asserts can go, as well. options.type
will always be set by the call to set_type(), and options.attr_value
will be set if -v was given on the command line.
Fixes T765
---
tools/crm_attribute.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/crm_attribute.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/crm_attribute.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/crm_attribute.c
@@ -197,7 +197,7 @@ static GOptionEntry selecting_entries[]
static GOptionEntry command_entries[] = {
{ "delete", 'D', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, delete_cb,
- "Delete the attribute/option",
+ "Delete the attribute/option (with -n or -P)",
NULL
},
@@ -208,7 +208,7 @@ static GOptionEntry command_entries[] =
},
{ "update", 'v', 0, G_OPTION_ARG_CALLBACK, update_cb,
- "Update the value of the attribute/option",
+ "Update the value of the attribute/option (with -n or -P)",
"VALUE"
},
@@ -513,10 +513,6 @@ command_update(pcmk__output_t *out, cib_
xmlNode *result = NULL;
bool use_pattern = options.attr_pattern != NULL;
- CRM_LOG_ASSERT(options.type != NULL);
- CRM_LOG_ASSERT(options.attr_name != NULL);
- CRM_LOG_ASSERT(options.attr_value != NULL);
-
/* See the comment in command_query regarding xpath and regular expressions. */
if (use_pattern) {
struct update_data_s ud = { out, cib, is_remote_node };
@@ -694,6 +690,14 @@ delete_used_correctly(void)
return options.command != 'D' || options.attr_name != NULL || options.attr_pattern != NULL;
}
+static bool
+update_used_correctly(void)
+{
+ return (options.command != 'u')
+ || (options.attr_name != NULL)
+ || (options.attr_pattern != NULL);
+}
+
static GOptionContext *
build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) {
GOptionContext *context = NULL;
@@ -874,6 +878,13 @@ main(int argc, char **argv)
goto done;
}
+ if (!update_used_correctly()) {
+ exit_code = CRM_EX_USAGE;
+ g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
+ "Error: must specify attribute name or pattern to update");
+ goto done;
+ }
+
if (options.attr_pattern) {
if (!pattern_used_correctly()) {
exit_code = CRM_EX_USAGE;