Blame SOURCES/012-string-arguments.patch

599c7d
From 2eee93e8f9ea2daa81769bc69843d63ced1a7112 Mon Sep 17 00:00:00 2001
599c7d
From: Chris Lumens <clumens@redhat.com>
599c7d
Date: Tue, 20 Jul 2021 16:39:07 -0400
599c7d
Subject: [PATCH 1/2] Low: tools: Audit command line options.
599c7d
599c7d
This just goes through and makes sure the command line options that take
599c7d
arguments are in the special parameter to pcmk__cmdline_preproc, and
599c7d
that options that do not take arguments are not.
599c7d
---
599c7d
 tools/crm_attribute.c | 2 +-
599c7d
 tools/crm_error.c     | 2 +-
599c7d
 tools/crm_resource.c  | 2 +-
599c7d
 tools/crm_rule.c      | 2 +-
599c7d
 tools/crm_simulate.c  | 2 +-
599c7d
 tools/crmadmin.c      | 2 +-
599c7d
 tools/stonith_admin.c | 2 +-
599c7d
 7 files changed, 7 insertions(+), 7 deletions(-)
599c7d
599c7d
diff --git a/tools/crm_attribute.c b/tools/crm_attribute.c
599c7d
index 8a5b4e4..6bd4e2a 100644
599c7d
--- a/tools/crm_attribute.c
599c7d
+++ b/tools/crm_attribute.c
599c7d
@@ -312,7 +312,7 @@ main(int argc, char **argv)
599c7d
 
599c7d
     GOptionGroup *output_group = NULL;
599c7d
     pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY);
599c7d
-    gchar **processed_args = pcmk__cmdline_preproc(argv, "DGNPdilnpstv");
599c7d
+    gchar **processed_args = pcmk__cmdline_preproc(argv, "NPUdilnpstv");
599c7d
     GOptionContext *context = build_arg_context(args, &output_group);
599c7d
 
599c7d
     if (!g_option_context_parse_strv(context, &processed_args, &error)) {
599c7d
diff --git a/tools/crm_error.c b/tools/crm_error.c
599c7d
index b4328ce..923f393 100644
599c7d
--- a/tools/crm_error.c
599c7d
+++ b/tools/crm_error.c
599c7d
@@ -79,7 +79,7 @@ main(int argc, char **argv)
599c7d
 
599c7d
     GOptionGroup *output_group = NULL;
599c7d
     pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY);
599c7d
-    gchar **processed_args = pcmk__cmdline_preproc(argv, "lrnX");
599c7d
+    gchar **processed_args = pcmk__cmdline_preproc(argv, NULL);
599c7d
     GOptionContext *context = build_arg_context(args, &output_group);
599c7d
 
599c7d
     if (!g_option_context_parse_strv(context, &processed_args, &error)) {
599c7d
diff --git a/tools/crm_resource.c b/tools/crm_resource.c
599c7d
index fa7902c..d8e140f 100644
599c7d
--- a/tools/crm_resource.c
599c7d
+++ b/tools/crm_resource.c
599c7d
@@ -1530,7 +1530,7 @@ main(int argc, char **argv)
599c7d
      */
599c7d
 
599c7d
     args = pcmk__new_common_args(SUMMARY);
599c7d
-    processed_args = pcmk__cmdline_preproc(argv, "GINSTdginpstuv");
599c7d
+    processed_args = pcmk__cmdline_preproc(argv, "GHINSTdginpstuvx");
599c7d
     context = build_arg_context(args, &output_group);
599c7d
 
599c7d
     pcmk__register_formats(output_group, formats);
599c7d
diff --git a/tools/crm_rule.c b/tools/crm_rule.c
599c7d
index 8b19bcd..30c5155 100644
599c7d
--- a/tools/crm_rule.c
599c7d
+++ b/tools/crm_rule.c
599c7d
@@ -239,7 +239,7 @@ main(int argc, char **argv)
599c7d
 
599c7d
     pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY);
599c7d
     GOptionContext *context = build_arg_context(args);
599c7d
-    gchar **processed_args = pcmk__cmdline_preproc(argv, "nopNO");
599c7d
+    gchar **processed_args = pcmk__cmdline_preproc(argv, "drX");
599c7d
 
599c7d
     if (!g_option_context_parse_strv(context, &processed_args, &error)) {
599c7d
         exit_code = CRM_EX_USAGE;
599c7d
diff --git a/tools/crm_simulate.c b/tools/crm_simulate.c
599c7d
index 0406bff..c83b1b1 100644
599c7d
--- a/tools/crm_simulate.c
599c7d
+++ b/tools/crm_simulate.c
599c7d
@@ -865,7 +865,7 @@ main(int argc, char **argv)
599c7d
 
599c7d
     GOptionGroup *output_group = NULL;
599c7d
     pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY);
599c7d
-    gchar **processed_args = pcmk__cmdline_preproc(argv, "bdefgiqrtuwxDFGINO");
599c7d
+    gchar **processed_args = pcmk__cmdline_preproc(argv, "bdefgiqrtuwxDFGINOP");
599c7d
     GOptionContext *context = build_arg_context(args, &output_group);
599c7d
 
599c7d
     /* This must come before g_option_context_parse_strv. */
599c7d
diff --git a/tools/crmadmin.c b/tools/crmadmin.c
599c7d
index 5cbde1b..b98f282 100644
599c7d
--- a/tools/crmadmin.c
599c7d
+++ b/tools/crmadmin.c
599c7d
@@ -188,7 +188,7 @@ main(int argc, char **argv)
599c7d
 
599c7d
     GOptionGroup *output_group = NULL;
599c7d
     pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY);
599c7d
-    gchar **processed_args = pcmk__cmdline_preproc(argv, "itBDEHKNPS");
599c7d
+    gchar **processed_args = pcmk__cmdline_preproc(argv, "itKNS");
599c7d
     GOptionContext *context = build_arg_context(args, &output_group);
599c7d
 
599c7d
     pcmk__register_formats(output_group, formats);
599c7d
diff --git a/tools/stonith_admin.c b/tools/stonith_admin.c
599c7d
index 6773cea..2d48326 100644
599c7d
--- a/tools/stonith_admin.c
599c7d
+++ b/tools/stonith_admin.c
599c7d
@@ -349,7 +349,7 @@ main(int argc, char **argv)
599c7d
 
599c7d
     GOptionGroup *output_group = NULL;
599c7d
     pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY);
599c7d
-    gchar **processed_args = pcmk__cmdline_preproc(argv, "adehilorstvBCDFHQRTU");
599c7d
+    gchar **processed_args = pcmk__cmdline_preproc(argv, "adehilorstvyBCDFHQRTU");
599c7d
     GOptionContext *context = build_arg_context(args, &output_group);
599c7d
 
599c7d
     pcmk__register_formats(output_group, formats);
599c7d
-- 
599c7d
1.8.3.1
599c7d
599c7d
599c7d
From 8301678ad1162450814d2fea5288aefe47a67a74 Mon Sep 17 00:00:00 2001
599c7d
From: Chris Lumens <clumens@redhat.com>
599c7d
Date: Tue, 20 Jul 2021 16:40:58 -0400
599c7d
Subject: [PATCH 2/2] Low: libcrmcommon: Also allow string arguments that start
599c7d
 with a dash.
599c7d
599c7d
There's various places where an option to a command line argument could
599c7d
itself be a valid command line argument.  For instance:
599c7d
599c7d
    crm_attribute -n crm_mon_options -v "-1i3"
599c7d
599c7d
The previous patching to pcmk__cmdline_preproc did not take this into
599c7d
account.  With this patch, options that are last in a string (or by
599c7d
themselves) and take an argument will have the next command line option
599c7d
grabbed and copied straight through without processing.
599c7d
599c7d
Regression in 2.1.0 caused by a long-standing bug in pcmk__cmdline_preproc.
599c7d
---
599c7d
 lib/common/cmdline.c                               |  8 ++++++
599c7d
 .../tests/cmdline/pcmk__cmdline_preproc_test.c     | 33 ++++++++++++++++++++++
599c7d
 2 files changed, 41 insertions(+)
599c7d
599c7d
diff --git a/lib/common/cmdline.c b/lib/common/cmdline.c
599c7d
index 9c1b810..1ca6147 100644
599c7d
--- a/lib/common/cmdline.c
599c7d
+++ b/lib/common/cmdline.c
599c7d
@@ -146,6 +146,7 @@ gchar **
599c7d
 pcmk__cmdline_preproc(char **argv, const char *special) {
599c7d
     GPtrArray *arr = NULL;
599c7d
     bool saw_dash_dash = false;
599c7d
+    bool copy_option = false;
599c7d
 
599c7d
     if (argv == NULL) {
599c7d
         return NULL;
599c7d
@@ -175,6 +176,12 @@ pcmk__cmdline_preproc(char **argv, const char *special) {
599c7d
             continue;
599c7d
         }
599c7d
 
599c7d
+        if (copy_option == true) {
599c7d
+            g_ptr_array_add(arr, g_strdup(argv[i]));
599c7d
+            copy_option = false;
599c7d
+            continue;
599c7d
+        }
599c7d
+
599c7d
         /* This is just a dash by itself.  That could indicate stdin/stdout, or
599c7d
          * it could be user error.  Copy it over and let glib figure it out.
599c7d
          */
599c7d
@@ -239,6 +246,7 @@ pcmk__cmdline_preproc(char **argv, const char *special) {
599c7d
                      */
599c7d
                     } else {
599c7d
                         g_ptr_array_add(arr, g_strdup_printf("-%c", *ch));
599c7d
+                        copy_option = true;
599c7d
                         ch++;
599c7d
                     }
599c7d
 
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 9a752ef..edc5640 100644
599c7d
--- a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
599c7d
+++ b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
599c7d
@@ -106,6 +106,36 @@ negative_score_2(void) {
599c7d
     g_strfreev(processed);
599c7d
 }
599c7d
 
599c7d
+static void
599c7d
+string_arg_with_dash(void) {
599c7d
+    const char *argv[] = { "-n", "crm_mon_options", "-v", "--opt1 --opt2", NULL };
599c7d
+    const gchar *expected[] = { "-n", "crm_mon_options", "-v", "--opt1 --opt2", 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
+string_arg_with_dash_2(void) {
599c7d
+    const char *argv[] = { "-n", "crm_mon_options", "-v", "-1i3", NULL };
599c7d
+    const gchar *expected[] = { "-n", "crm_mon_options", "-v", "-1i3", 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
+string_arg_with_dash_3(void) {
599c7d
+    const char *argv[] = { "-abc", "-1i3", NULL };
599c7d
+    const gchar *expected[] = { "-a", "-b", "-c", "-1i3", NULL };
599c7d
+
599c7d
+    gchar **processed = pcmk__cmdline_preproc((char **) argv, "c");
599c7d
+    LISTS_EQ(processed, expected);
599c7d
+    g_strfreev(processed);
599c7d
+}
599c7d
+
599c7d
 int
599c7d
 main(int argc, char **argv)
599c7d
 {
599c7d
@@ -120,5 +150,8 @@ main(int argc, char **argv)
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
+    g_test_add_func("/common/cmdline/preproc/string_arg_with_dash", string_arg_with_dash);
599c7d
+    g_test_add_func("/common/cmdline/preproc/string_arg_with_dash_2", string_arg_with_dash_2);
599c7d
+    g_test_add_func("/common/cmdline/preproc/string_arg_with_dash_3", string_arg_with_dash_3);
599c7d
     return g_test_run();
599c7d
 }
599c7d
-- 
599c7d
1.8.3.1
599c7d