Blame SOURCES/005-feature-set.patch

c563b9
From 477b7b679d58455dc38c2594b29a1ecfbe88e80c Mon Sep 17 00:00:00 2001
c563b9
From: Chris Lumens <clumens@redhat.com>
c563b9
Date: Mon, 2 Nov 2020 14:55:27 -0500
c563b9
Subject: [PATCH 1/2] Fix: libcrmcommon: Prevent a segfault in
c563b9
 pcmk__cmdline_preproc.
c563b9
c563b9
The list of special single-character args is optional.  The function
c563b9
currently handles it being an empty string, but it should handle a NULL
c563b9
as well.
c563b9
---
c563b9
 lib/common/cmdline.c | 2 +-
c563b9
 1 file changed, 1 insertion(+), 1 deletion(-)
c563b9
c563b9
diff --git a/lib/common/cmdline.c b/lib/common/cmdline.c
c563b9
index d66ccc7..66f1976 100644
c563b9
--- a/lib/common/cmdline.c
c563b9
+++ b/lib/common/cmdline.c
c563b9
@@ -203,7 +203,7 @@ pcmk__cmdline_preproc(char **argv, const char *special) {
c563b9
                  * glib does not.  Grab both the argument and its value and
c563b9
                  * separate them into a new argument.
c563b9
                  */
c563b9
-                if (strchr(special, *ch) != NULL) {
c563b9
+                if (special != NULL && strchr(special, *ch) != NULL) {
c563b9
                     /* The argument does not occur at the end of this string of
c563b9
                      * arguments.  Take everything through the end as its value.
c563b9
                      */
c563b9
-- 
c563b9
1.8.3.1
c563b9
c563b9
c563b9
From d1f4a975fa783045254521f415f1899b34ee96e3 Mon Sep 17 00:00:00 2001
c563b9
From: Chris Lumens <clumens@redhat.com>
c563b9
Date: Mon, 2 Nov 2020 16:06:29 -0500
c563b9
Subject: [PATCH 2/2] Test: libcrmcommon: Add unit tests for
c563b9
 pcmk__cmdline_preproc.
c563b9
c563b9
---
c563b9
 configure.ac                                       |   1 +
c563b9
 lib/common/tests/Makefile.am                       |   2 +-
c563b9
 lib/common/tests/cmdline/Makefile.am               |  29 ++++++
c563b9
 .../tests/cmdline/pcmk__cmdline_preproc_test.c     | 102 +++++++++++++++++++++
c563b9
 4 files changed, 133 insertions(+), 1 deletion(-)
c563b9
 create mode 100644 lib/common/tests/cmdline/Makefile.am
c563b9
 create mode 100644 lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
c563b9
c563b9
diff --git a/configure.ac b/configure.ac
c563b9
index 7ed4a30..36e85a9 100644
c563b9
--- a/configure.ac
c563b9
+++ b/configure.ac
c563b9
@@ -2006,6 +2006,7 @@ AC_CONFIG_FILES(Makefile                                            \
c563b9
                 lib/pacemaker-cluster.pc                            \
c563b9
                 lib/common/Makefile                                 \
c563b9
                 lib/common/tests/Makefile                           \
c563b9
+                lib/common/tests/cmdline/Makefile                   \
c563b9
                 lib/common/tests/flags/Makefile                     \
c563b9
                 lib/common/tests/operations/Makefile                \
c563b9
                 lib/common/tests/strings/Makefile                   \
c563b9
diff --git a/lib/common/tests/Makefile.am b/lib/common/tests/Makefile.am
c563b9
index 33c45cb..f3eaeec 100644
c563b9
--- a/lib/common/tests/Makefile.am
c563b9
+++ b/lib/common/tests/Makefile.am
c563b9
@@ -1 +1 @@
c563b9
-SUBDIRS = flags operations strings utils
c563b9
+SUBDIRS = cmdline flags operations strings utils
c563b9
diff --git a/lib/common/tests/cmdline/Makefile.am b/lib/common/tests/cmdline/Makefile.am
c563b9
new file mode 100644
c563b9
index 0000000..e69ef21
c563b9
--- /dev/null
c563b9
+++ b/lib/common/tests/cmdline/Makefile.am
c563b9
@@ -0,0 +1,29 @@
c563b9
+#
c563b9
+# Copyright 2020 the Pacemaker project contributors
c563b9
+#
c563b9
+# The version control history for this file may have further details.
c563b9
+#
c563b9
+# This source code is licensed under the GNU General Public License version 2
c563b9
+# or later (GPLv2+) WITHOUT ANY WARRANTY.
c563b9
+#
c563b9
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
c563b9
+LDADD = $(top_builddir)/lib/common/libcrmcommon.la
c563b9
+
c563b9
+include $(top_srcdir)/mk/glib-tap.mk
c563b9
+
c563b9
+# Add each test program here.  Each test should be written as a little standalone
c563b9
+# program using the glib unit testing functions.  See the documentation for more
c563b9
+# information.
c563b9
+#
c563b9
+# https://developer.gnome.org/glib/unstable/glib-Testing.html
c563b9
+#
c563b9
+# Add "_test" to the end of all test program names to simplify .gitignore.
c563b9
+test_programs = pcmk__cmdline_preproc_test
c563b9
+
c563b9
+# If any extra data needs to be added to the source distribution, add it to the
c563b9
+# following list.
c563b9
+dist_test_data =
c563b9
+
c563b9
+# If any extra data needs to be used by tests but should not be added to the
c563b9
+# source distribution, add it to the following list.
c563b9
+test_data =
c563b9
diff --git a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
c563b9
new file mode 100644
c563b9
index 0000000..e13c983
c563b9
--- /dev/null
c563b9
+++ b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
c563b9
@@ -0,0 +1,102 @@
c563b9
+/*
c563b9
+ * Copyright 2020 the Pacemaker project contributors
c563b9
+ *
c563b9
+ * The version control history for this file may have further details.
c563b9
+ *
c563b9
+ * This source code is licensed under the GNU Lesser General Public License
c563b9
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
c563b9
+ */
c563b9
+
c563b9
+#include <crm_internal.h>
c563b9
+#include <crm/common/cmdline_internal.h>
c563b9
+
c563b9
+#define LISTS_EQ(a, b) { \
c563b9
+    g_assert_cmpint(g_strv_length((gchar **) (a)), ==, g_strv_length((gchar **) (b))); \
c563b9
+    for (int i = 0; i < g_strv_length((a)); i++) { \
c563b9
+        g_assert_cmpstr((a)[i], ==, (b)[i]); \
c563b9
+    } \
c563b9
+}
c563b9
+
c563b9
+static void
c563b9
+empty_input(void) {
c563b9
+    g_assert_cmpint(pcmk__cmdline_preproc(NULL, "") == NULL, ==, TRUE);
c563b9
+}
c563b9
+
c563b9
+static void
c563b9
+no_specials(void) {
c563b9
+    const char *argv[] = { "-a", "-b", "-c", "-d", NULL };
c563b9
+    const gchar *expected[] = { "-a", "-b", "-c", "-d", NULL };
c563b9
+
c563b9
+    gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
c563b9
+    LISTS_EQ(processed, expected);
c563b9
+    g_strfreev(processed);
c563b9
+
c563b9
+    processed = pcmk__cmdline_preproc((char **) argv, "");
c563b9
+    LISTS_EQ(processed, expected);
c563b9
+    g_strfreev(processed);
c563b9
+}
c563b9
+
c563b9
+static void
c563b9
+single_dash(void) {
c563b9
+    const char *argv[] = { "-", NULL };
c563b9
+    const gchar *expected[] = { "-", NULL };
c563b9
+
c563b9
+    gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
c563b9
+    LISTS_EQ(processed, expected);
c563b9
+    g_strfreev(processed);
c563b9
+}
c563b9
+
c563b9
+static void
c563b9
+double_dash(void) {
c563b9
+    const char *argv[] = { "-a", "--", "-bc", NULL };
c563b9
+    const gchar *expected[] = { "-a", "--", "-bc", NULL };
c563b9
+
c563b9
+    gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
c563b9
+    LISTS_EQ(processed, expected);
c563b9
+    g_strfreev(processed);
c563b9
+}
c563b9
+
c563b9
+static void
c563b9
+special_args(void) {
c563b9
+    const char *argv[] = { "-aX", "-Fval", NULL };
c563b9
+    const gchar *expected[] = { "-a", "X", "-F", "val", NULL };
c563b9
+
c563b9
+    gchar **processed = pcmk__cmdline_preproc((char **) argv, "aF");
c563b9
+    LISTS_EQ(processed, expected);
c563b9
+    g_strfreev(processed);
c563b9
+}
c563b9
+
c563b9
+static void
c563b9
+special_arg_at_end(void) {
c563b9
+    const char *argv[] = { "-a", NULL };
c563b9
+    const gchar *expected[] = { "-a", NULL };
c563b9
+
c563b9
+    gchar **processed = pcmk__cmdline_preproc((char **) argv, "a");
c563b9
+    LISTS_EQ(processed, expected);
c563b9
+    g_strfreev(processed);
c563b9
+}
c563b9
+
c563b9
+static void
c563b9
+long_arg(void) {
c563b9
+    const char *argv[] = { "--blah=foo", NULL };
c563b9
+    const gchar *expected[] = { "--blah=foo", NULL };
c563b9
+
c563b9
+    gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
c563b9
+    LISTS_EQ(processed, expected);
c563b9
+    g_strfreev(processed);
c563b9
+}
c563b9
+
c563b9
+int
c563b9
+main(int argc, char **argv)
c563b9
+{
c563b9
+    g_test_init(&argc, &argv, NULL);
c563b9
+
c563b9
+    g_test_add_func("/common/cmdline/preproc/empty_input", empty_input);
c563b9
+    g_test_add_func("/common/cmdline/preproc/no_specials", no_specials);
c563b9
+    g_test_add_func("/common/cmdline/preproc/single_dash", single_dash);
c563b9
+    g_test_add_func("/common/cmdline/preproc/double_dash", double_dash);
c563b9
+    g_test_add_func("/common/cmdline/preproc/special_args", special_args);
c563b9
+    g_test_add_func("/common/cmdline/preproc/special_arg_at_end", special_arg_at_end);
c563b9
+    g_test_add_func("/common/cmdline/preproc/long_arg", long_arg);
c563b9
+    return g_test_run();
c563b9
+}
c563b9
-- 
c563b9
1.8.3.1
c563b9