Blame SOURCES/findutils-4.6.0-internal-noop.patch

2b3154
From d844b7bbf3952998a906f21ba432aa62a3b9c7c6 Mon Sep 17 00:00:00 2001
2b3154
From: Bernhard Voelker <mail@bernhard-voelker.de>
2b3154
Date: Tue, 14 Jun 2016 20:49:42 +0200
2b3154
Subject: [PATCH] Fix bug #48180: find: avoid segfault for internal '-noop'
2b3154
 option
2b3154
2b3154
The pseudo-option '-noop' was never meant to be exposed to the user
2b3154
interface.  If specified by the user, find(1) segfaulted.
2b3154
Bug introduced in commit FINDUTILS_4_3_0-1-12-g6b8a4db.
2b3154
2b3154
* find/parser.c (struct parser_table): Rename the parser_name element of
2b3154
the ARG_NOOP entry from 'noop' to '--noop', thus indicating its pure
2b3154
internal character.
2b3154
(found_parser): Return NULL when the user has passed the '---noop' option;
2b3154
the caller does the error handling.
2b3154
* find/testsuite/sv-48180-refuse-noop.sh: Add test.
2b3154
* find/testsuite/Makefile.am (test_shell_progs): Reference the test.
2b3154
* NEWS (Bug fixes): Document the fix.
2b3154
2b3154
Reported by Tavian Barnes <tavianator@tavianator.com> in
2b3154
    https://savannah.gnu.org/bugs/?48180
2b3154
2b3154
Upstream-commit: 595060f28eb5f658fa8d98970959c617fab0f078
2b3154
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
2b3154
---
2b3154
 find/parser.c                          |   6 +-
2b3154
 find/testsuite/Makefile.am             |   3 +-
2b3154
 find/testsuite/sv-48180-refuse-noop.sh | 117 +++++++++++++++++++++++++++++++++
2b3154
 3 files changed, 124 insertions(+), 2 deletions(-)
2b3154
 create mode 100644 find/testsuite/sv-48180-refuse-noop.sh
2b3154
2b3154
diff --git a/find/parser.c b/find/parser.c
2b3154
index 2d45349..697b2a2 100644
2b3154
--- a/find/parser.c
2b3154
+++ b/find/parser.c
2b3154
@@ -321,7 +321,8 @@ static struct parser_table const parse_table[] =
2b3154
    */
2b3154
   {ARG_TEST, "false",                 parse_false,   pred_false}, /* GNU */
2b3154
   {ARG_TEST, "true",                  parse_true,    pred_true }, /* GNU */
2b3154
-  {ARG_NOOP, "noop",                  NULL,          pred_true }, /* GNU, internal use only */
2b3154
+  /* Internal pseudo-option, therefore 3 minus: ---noop.  */
2b3154
+  {ARG_NOOP, "--noop",                NULL,          pred_true }, /* GNU, internal use only */
2b3154
 
2b3154
   /* Various other cases that don't fit neatly into our macro scheme. */
2b3154
   {ARG_TEST, "help",                  parse_help,    NULL},       /* GNU */
2b3154
@@ -596,6 +597,9 @@ found_parser (const char *original_arg, const struct parser_table *entry)
2b3154
    */
2b3154
   if (entry->type != ARG_POSITIONAL_OPTION)
2b3154
     {
2b3154
+      if (entry->type == ARG_NOOP)
2b3154
+        return NULL;  /* internal use only, trap -noop here.  */
2b3154
+
2b3154
       /* Something other than -follow/-daystart.
2b3154
        * If this is an option, check if it followed
2b3154
        * a non-option and if so, issue a warning.
2b3154
diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am
2b3154
index ab5dbe8..1371c70 100644
2b3154
--- a/find/testsuite/Makefile.am
2b3154
+++ b/find/testsuite/Makefile.am
2b3154
@@ -259,7 +259,8 @@ test_escape_c.sh \
2b3154
 test_inode.sh \
2b3154
 sv-34079.sh \
2b3154
 sv-34976-execdir-fd-leak.sh \
2b3154
-sv-48030-exec-plus-bug.sh
2b3154
+sv-48030-exec-plus-bug.sh \
2b3154
+sv-48180-refuse-noop.sh
2b3154
 
2b3154
 EXTRA_DIST = $(EXTRA_DIST_EXP) $(EXTRA_DIST_XO) $(EXTRA_DIST_GOLDEN) \
2b3154
 	$(test_shell_progs) binary_locations.sh checklists.py
2b3154
diff --git a/find/testsuite/sv-48180-refuse-noop.sh b/find/testsuite/sv-48180-refuse-noop.sh
2b3154
new file mode 100755
2b3154
index 0000000..974f0f0
2b3154
--- /dev/null
2b3154
+++ b/find/testsuite/sv-48180-refuse-noop.sh
2b3154
@@ -0,0 +1,117 @@
2b3154
+#! /bin/sh
2b3154
+# Copyright (C) 2016 Free Software Foundation, Inc.
2b3154
+#
2b3154
+# This program is free software: you can redistribute it and/or modify
2b3154
+# it under the terms of the GNU General Public License as published by
2b3154
+# the Free Software Foundation, either version 3 of the License, or
2b3154
+# (at your option) any later version.
2b3154
+#
2b3154
+# This program is distributed in the hope that it will be useful,
2b3154
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2b3154
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2b3154
+# GNU General Public License for more details.
2b3154
+#
2b3154
+# You should have received a copy of the GNU General Public License
2b3154
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2b3154
+#
2b3154
+
2b3154
+# This test verifies that find refuses the internal -noop, ---noop option.
2b3154
+# Between findutils-4.3.1 and 4.6, find dumped core ($? = 139).
2b3154
+
2b3154
+testname="$(basename $0)"
2b3154
+
2b3154
+. "${srcdir}"/binary_locations.sh
2b3154
+
2b3154
+die() {
2b3154
+  echo "$@" >&2
2b3154
+  exit 1
2b3154
+}
2b3154
+
2b3154
+# This is used to simplify checking of the return value
2b3154
+# which is useful when ensuring a command fails as desired.
2b3154
+# I.e., just doing `command ... &&fail=1` will not catch
2b3154
+# a segfault in command for example.  With this helper you
2b3154
+# instead check an explicit exit code like
2b3154
+#   returns_ 1 command ... || fail
2b3154
+returns_ () {
2b3154
+  # Disable tracing so it doesn't interfere with stderr of the wrapped command
2b3154
+  { set +x; } 2>/dev/null
2b3154
+
2b3154
+  local exp_exit="$1"
2b3154
+  shift
2b3154
+  "$@"
2b3154
+  test $? -eq $exp_exit && ret_=0 || ret_=1
2b3154
+
2b3154
+  set -x
2b3154
+  { return $ret_; } 2>/dev/null
2b3154
+}
2b3154
+
2b3154
+# Define the nicest compare available (borrowed from gnulib).
2b3154
+if diff_out_=`exec 2>/dev/null; diff -u "$0" "$0" < /dev/null` \
2b3154
+   && diff -u Makefile "$0" 2>/dev/null | grep '^[+]#!' >/dev/null; then
2b3154
+  # diff accepts the -u option and does not (like AIX 7 'diff') produce an
2b3154
+  # extra space on column 1 of every content line.
2b3154
+  if test -z "$diff_out_"; then
2b3154
+    compare () { diff -u "$@"; }
2b3154
+  else
2b3154
+    compare ()
2b3154
+    {
2b3154
+      if diff -u "$@" > diff.out; then
2b3154
+        # No differences were found, but Solaris 'diff' produces output
2b3154
+        # "No differences encountered". Hide this output.
2b3154
+        rm -f diff.out
2b3154
+        true
2b3154
+      else
2b3154
+        cat diff.out
2b3154
+        rm -f diff.out
2b3154
+        false
2b3154
+      fi
2b3154
+    }
2b3154
+  fi
2b3154
+elif diff_out_=`exec 2>/dev/null; diff -c "$0" "$0" < /dev/null`; then
2b3154
+  if test -z "$diff_out_"; then
2b3154
+    compare () { diff -c "$@"; }
2b3154
+  else
2b3154
+    compare ()
2b3154
+    {
2b3154
+      if diff -c "$@" > diff.out; then
2b3154
+        # No differences were found, but AIX and HP-UX 'diff' produce output
2b3154
+        # "No differences encountered" or "There are no differences between the
2b3154
+        # files.". Hide this output.
2b3154
+        rm -f diff.out
2b3154
+        true
2b3154
+      else
2b3154
+        cat diff.out
2b3154
+        rm -f diff.out
2b3154
+        false
2b3154
+      fi
2b3154
+    }
2b3154
+  fi
2b3154
+elif cmp -s /dev/null /dev/null 2>/dev/null; then
2b3154
+  compare () { cmp -s "$@"; }
2b3154
+else
2b3154
+  compare () { cmp "$@"; }
2b3154
+fi
2b3154
+
2b3154
+set -x
2b3154
+tmpdir="$(mktemp -d)" \
2b3154
+  && cd "$tmpdir" \
2b3154
+  || die "FAIL: failed to set up the test in ${tmpdir}"
2b3154
+
2b3154
+fail=0
2b3154
+# Exercise both the previous name of the pseudo-option '-noop',
2b3154
+# and the now renamed '---noop' option for both find executables.
2b3154
+for exe in "${ftsfind}" "${oldfind}"; do
2b3154
+  for opt in 'noop' '--noop'; do
2b3154
+    out="${exe}${opt}.out"
2b3154
+    err="${exe}${opt}.err"
2b3154
+    returns_ 1 "$exe" "-${opt}" >"$out" 2> "$err" || fail=1
2b3154
+    compare /dev/null "$out" || fail=1
2b3154
+    grep "find: unknown predicate .-${opt}." "$err" \
2b3154
+      || { cat "$err"; fail=1; }
2b3154
+  done
2b3154
+done
2b3154
+
2b3154
+cd ..
2b3154
+rm -rf "$tmpdir" || exit 1
2b3154
+exit $fail
2b3154
-- 
2b3154
2.5.5
2b3154