Blame SOURCES/011-crm_attribute-regression.patch

599c7d
From ea5510dd979bb6d375324cda26925d9e7c4362f5 Mon Sep 17 00:00:00 2001
599c7d
From: Chris Lumens <clumens@redhat.com>
599c7d
Date: Mon, 19 Jul 2021 10:04:16 -0400
599c7d
Subject: [PATCH 1/2] Low: tools: The --get-value option does not require an
599c7d
 arg.
599c7d
599c7d
Regression in 2.1.0 introduced by 15f5c2901.
599c7d
---
599c7d
 tools/crm_attribute.c | 2 +-
599c7d
 1 file changed, 1 insertion(+), 1 deletion(-)
599c7d
599c7d
diff --git a/tools/crm_attribute.c b/tools/crm_attribute.c
599c7d
index 2cc8d26..8a5b4e4 100644
599c7d
--- a/tools/crm_attribute.c
599c7d
+++ b/tools/crm_attribute.c
599c7d
@@ -242,7 +242,7 @@ static GOptionEntry deprecated_entries[] = {
599c7d
       NULL, NULL
599c7d
     },
599c7d
 
599c7d
-    { "get-value", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, value_cb,
599c7d
+    { "get-value", 0, G_OPTION_FLAG_HIDDEN|G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, value_cb,
599c7d
       NULL, NULL
599c7d
     },
599c7d
 
599c7d
-- 
599c7d
1.8.3.1
599c7d
599c7d
599c7d
From ef054d943afe8e60017f6adc4e25f88a59ac91a4 Mon Sep 17 00:00:00 2001
599c7d
From: Chris Lumens <clumens@redhat.com>
599c7d
Date: Mon, 19 Jul 2021 11:37:04 -0400
599c7d
Subject: [PATCH 2/2] Low: libcrmcommon: Allow negative numbers as cmdline
599c7d
 options.
599c7d
599c7d
The bug here is that negative numbers (for instance, negative scores)
599c7d
are not supported as command line arguments.  Because we break up a
599c7d
string that starts with a single dash into multiple arguments, "-1000"
599c7d
becomes "-1", "-0", "-0", and "-0".
599c7d
599c7d
Because we don't have enough information about what is happening on the
599c7d
command line, the best we can do here is recognize something as a
599c7d
negative number and pass it on.  Any errors will have to be detected at
599c7d
a later step.
599c7d
599c7d
Also note that we only recognize negative numbers if they start with
599c7d
1-9.  Starting with 0 will be recognized as some sort of string.
599c7d
599c7d
Regression in 2.1.0 caused by a long-standing bug in
599c7d
pcmk__cmdline_preproc_test.
599c7d
---
599c7d
 lib/common/cmdline.c                               | 29 ++++++++++++++++++++++
599c7d
 .../tests/cmdline/pcmk__cmdline_preproc_test.c     | 24 +++++++++++++++++-
599c7d
 2 files changed, 52 insertions(+), 1 deletion(-)
599c7d
599c7d
diff --git a/lib/common/cmdline.c b/lib/common/cmdline.c
599c7d
index 7c95d02..9c1b810 100644
599c7d
--- a/lib/common/cmdline.c
599c7d
+++ b/lib/common/cmdline.c
599c7d
@@ -9,6 +9,7 @@
599c7d
 
599c7d
 #include <crm_internal.h>
599c7d
 
599c7d
+#include <ctype.h>
599c7d
 #include <glib.h>
599c7d
 
599c7d
 #include <crm/crm.h>
599c7d
@@ -189,6 +190,34 @@ pcmk__cmdline_preproc(char **argv, const char *special) {
599c7d
             /* Skip over leading dash */
599c7d
             char *ch = argv[i]+1;
599c7d
 
599c7d
+            /* This looks like the start of a number, which means it is a negative
599c7d
+             * number.  It's probably the argument to the preceeding option, but
599c7d
+             * we can't know that here.  Copy it over and let whatever handles
599c7d
+             * arguments next figure it out.
599c7d
+             */
599c7d
+            if (*ch != '\0' && *ch >= '1' && *ch <= '9') {
599c7d
+                bool is_numeric = true;
599c7d
+
599c7d
+                while (*ch != '\0') {
599c7d
+                    if (!isdigit(*ch)) {
599c7d
+                        is_numeric = false;
599c7d
+                        break;
599c7d
+                    }
599c7d
+
599c7d
+                    ch++;
599c7d
+                }
599c7d
+
599c7d
+                if (is_numeric) {
599c7d
+                    g_ptr_array_add(arr, g_strdup_printf("%s", argv[i]));
599c7d
+                    continue;
599c7d
+                } else {
599c7d
+                    /* This argument wasn't entirely numeric.  Reset ch to the
599c7d
+                     * beginning so we can process it one character at a time.
599c7d
+                     */
599c7d
+                    ch = argv[i]+1;
599c7d
+                }
599c7d
+            }
599c7d
+
599c7d
             while (*ch != '\0') {
599c7d
                 /* This is a special short argument that takes an option.  getopt
599c7d
                  * allows values to be interspersed with a list of arguments, but
599c7d
diff --git a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
599c7d
index b8506c6..9a752ef 100644
599c7d
--- a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
599c7d
+++ b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
599c7d
@@ -1,5 +1,5 @@
599c7d
 /*
599c7d
- * Copyright 2020 the Pacemaker project contributors
599c7d
+ * Copyright 2020-2021 the Pacemaker project contributors
599c7d
  *
599c7d
  * The version control history for this file may have further details.
599c7d
  *
599c7d
@@ -86,6 +86,26 @@ long_arg(void) {
599c7d
     g_strfreev(processed);
599c7d
 }
599c7d
 
599c7d
+static void
599c7d
+negative_score(void) {
599c7d
+    const char *argv[] = { "-v", "-1000", NULL };
599c7d
+    const gchar *expected[] = { "-v", "-1000", NULL };
599c7d
+
599c7d
+    gchar **processed = pcmk__cmdline_preproc((char **) argv, "v");
599c7d
+    LISTS_EQ(processed, expected);
599c7d
+    g_strfreev(processed);
599c7d
+}
599c7d
+
599c7d
+static void
599c7d
+negative_score_2(void) {
599c7d
+    const char *argv[] = { "-1i3", NULL };
599c7d
+    const gchar *expected[] = { "-1", "-i", "-3", NULL };
599c7d
+
599c7d
+    gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
599c7d
+    LISTS_EQ(processed, expected);
599c7d
+    g_strfreev(processed);
599c7d
+}
599c7d
+
599c7d
 int
599c7d
 main(int argc, char **argv)
599c7d
 {
599c7d
@@ -98,5 +118,7 @@ main(int argc, char **argv)
599c7d
     g_test_add_func("/common/cmdline/preproc/special_args", special_args);
599c7d
     g_test_add_func("/common/cmdline/preproc/special_arg_at_end", special_arg_at_end);
599c7d
     g_test_add_func("/common/cmdline/preproc/long_arg", long_arg);
599c7d
+    g_test_add_func("/common/cmdline/preproc/negative_score", negative_score);
599c7d
+    g_test_add_func("/common/cmdline/preproc/negative_score_2", negative_score_2);
599c7d
     return g_test_run();
599c7d
 }
599c7d
-- 
599c7d
1.8.3.1
599c7d