Blame SOURCES/012-string-arguments.patch

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