Compare commits

...

3 Commits
rawhide ... f23

4 changed files with 504 additions and 3 deletions

View File

@ -1,7 +1,7 @@
From 1328926a705fdb4728c1f255dd368de928736d39 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Fri, 25 Sep 2015 16:09:39 +0200
Subject: [PATCH 3/4] fts: introduce the FTS_NOLEAF flag
Subject: [PATCH 1/3] fts: introduce the FTS_NOLEAF flag
The flag is needed to implement the -noleaf option of find.
* lib/fts.c (link_count_optimize_ok): Implement the FTS_NOLEAF flag.
@ -57,7 +57,7 @@ index 63d4b74..f1d519b 100644
From c186934e6e37ddadf7511abb9b1045192757618e Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Fri, 25 Sep 2015 19:13:15 +0200
Subject: [PATCH 4/4] ftsfind: propagate the -noleaf option to FTS
Subject: [PATCH 2/3] ftsfind: propagate the -noleaf option to FTS
* find/ftsfind.c (find): Propagate the -noleaf option to FTS.
---
@ -81,3 +81,61 @@ index 5159470..e34b672 100644
--
2.5.0
From 2edb6204bab0acb0ef8cdde7499396afd9c66131 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
Date: Mon, 18 Jan 2016 17:29:28 +0000
Subject: [PATCH 3/3] fts: don't unconditionally use leaf optimization for NFS
NFS st_nlink are not accurate on all implementations,
leading to aborts() if that assumption is made.
See <https://bugzilla.redhat.com/1299169>
* lib/fts.c (leaf_optimization_applies): Remove NFS from
the white list, and document the issue.
Upstream-commit: 85717b68b03bf85016c5079fbbf0c8aa2b182ba6
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
gl/lib/fts.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/gl/lib/fts.c b/gl/lib/fts.c
index 55cd554..6e1eaf5 100644
--- a/gl/lib/fts.c
+++ b/gl/lib/fts.c
@@ -718,22 +718,23 @@ leaf_optimization_applies (int dir_fd)
switch (fs_buf.f_type)
{
- case S_MAGIC_NFS:
- /* NFS provides usable dirent.d_type but not necessarily for all entries
- of large directories. See <https://bugzilla.redhat.com/1252549>. */
- return true;
-
/* List here the file system types that lack usable dirent.d_type
info, yet for which the optimization does apply. */
case S_MAGIC_REISERFS:
case S_MAGIC_XFS:
return true;
+ /* Explicitly list here any other file system type for which the
+ optimization is not applicable, but need documentation. */
+ case S_MAGIC_NFS:
+ /* NFS provides usable dirent.d_type but not necessarily for all entries
+ of large directories, so as per <https://bugzilla.redhat.com/1252549>
+ NFS should return true. However st_nlink values are not accurate on
+ all implementations as per <https://bugzilla.redhat.com/1299169>. */
+ /* fall through */
case S_MAGIC_PROC:
- /* Explicitly listing this or any other file system type for which
- the optimization is not applicable is not necessary, but we leave
- it here to document the risk. Per http://bugs.debian.org/143111,
- /proc may have bogus stat.st_nlink values. */
+ /* Per <http://bugs.debian.org/143111> /proc may have
+ bogus stat.st_nlink values. */
/* fall through */
default:
return false;
--
2.5.5

View File

@ -0,0 +1,226 @@
From 443166adaf1c8b91e16a716f3b13f47493b895cc Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <mail@bernhard-voelker.de>
Date: Tue, 31 May 2016 10:38:52 +0200
Subject: [PATCH] Fix bug #48030: find: -exec + does not pass all arguments in
certain cases
When the -exec arguments buffer (usually 128k) is full and the given
command has been executed with all that arguments, find(1) missed to
execute the command yet another time if only 1 another file would have
to be processed.
Both find(1), i.e., nowadays FTS-version, and oldfind are affected.
This bug was present since the implementation of '-exec +' in 2005,
see commit FINDUTILS_4_2_11-1-25-gf0a6ac6.
* lib/buildcmd.c (bc_push_arg): Move the assignment to set 'state->todo'
to 1 down after the immediate execution which resets that flag.
* find/testsuite/sv-48030-exec-plus-bug.sh: Add a test.
* find/testsuite/Makefile.am (test_shell_progs): Reference the test.
* NEWS (Bug Fixes): Mention the fix.
Reported by Joe Philip Ninan <indiajoe@gmail.com> in
https://savannah.gnu.org/bugs/?48030
Upstream-commit: 8cdc9767e305c9566f537af9d1acf71d1bc6ee8e
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
find/testsuite/Makefile.am | 3 +-
find/testsuite/sv-48030-exec-plus-bug.sh | 143 +++++++++++++++++++++++++++++++
lib/buildcmd.c | 10 +--
3 files changed, 150 insertions(+), 6 deletions(-)
create mode 100644 find/testsuite/sv-48030-exec-plus-bug.sh
diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am
index c1369c3..ab5dbe8 100644
--- a/find/testsuite/Makefile.am
+++ b/find/testsuite/Makefile.am
@@ -258,7 +258,8 @@ test_escapechars.sh \
test_escape_c.sh \
test_inode.sh \
sv-34079.sh \
-sv-34976-execdir-fd-leak.sh
+sv-34976-execdir-fd-leak.sh \
+sv-48030-exec-plus-bug.sh
EXTRA_DIST = $(EXTRA_DIST_EXP) $(EXTRA_DIST_XO) $(EXTRA_DIST_GOLDEN) \
$(test_shell_progs) binary_locations.sh checklists.py
diff --git a/find/testsuite/sv-48030-exec-plus-bug.sh b/find/testsuite/sv-48030-exec-plus-bug.sh
new file mode 100644
index 0000000..4dbf149
--- /dev/null
+++ b/find/testsuite/sv-48030-exec-plus-bug.sh
@@ -0,0 +1,143 @@
+#! /bin/sh
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# This test verifies that find invokes the given command for the
+# multiple-argument sytax '-exec CMD {} +'. Between FINDUTILS-4.2.12
+# and v4.6.0, find(1) would have failed to execute CMD another time
+# if there was only one last single file argument.
+
+testname="$(basename $0)"
+
+. "${srcdir}"/binary_locations.sh
+
+die() {
+ echo "$@" >&2
+ exit 1
+}
+
+# This is used to simplify checking of the return value
+# which is useful when ensuring a command fails as desired.
+# I.e., just doing `command ... &&fail=1` will not catch
+# a segfault in command for example. With this helper you
+# instead check an explicit exit code like
+# returns_ 1 command ... || fail
+returns_ () {
+ # Disable tracing so it doesn't interfere with stderr of the wrapped command
+ { set +x; } 2>/dev/null
+
+ local exp_exit="$1"
+ shift
+ "$@"
+ test $? -eq $exp_exit && ret_=0 || ret_=1
+
+ set -x
+ { return $ret_; } 2>/dev/null
+}
+
+# Define the nicest compare available (borrowed from gnulib).
+if diff_out_=`exec 2>/dev/null; diff -u "$0" "$0" < /dev/null` \
+ && diff -u Makefile "$0" 2>/dev/null | grep '^[+]#!' >/dev/null; then
+ # diff accepts the -u option and does not (like AIX 7 'diff') produce an
+ # extra space on column 1 of every content line.
+ if test -z "$diff_out_"; then
+ compare () { diff -u "$@"; }
+ else
+ compare ()
+ {
+ if diff -u "$@" > diff.out; then
+ # No differences were found, but Solaris 'diff' produces output
+ # "No differences encountered". Hide this output.
+ rm -f diff.out
+ true
+ else
+ cat diff.out
+ rm -f diff.out
+ false
+ fi
+ }
+ fi
+elif diff_out_=`exec 2>/dev/null; diff -c "$0" "$0" < /dev/null`; then
+ if test -z "$diff_out_"; then
+ compare () { diff -c "$@"; }
+ else
+ compare ()
+ {
+ if diff -c "$@" > diff.out; then
+ # No differences were found, but AIX and HP-UX 'diff' produce output
+ # "No differences encountered" or "There are no differences between the
+ # files.". Hide this output.
+ rm -f diff.out
+ true
+ else
+ cat diff.out
+ rm -f diff.out
+ false
+ fi
+ }
+ fi
+elif cmp -s /dev/null /dev/null 2>/dev/null; then
+ compare () { cmp -s "$@"; }
+else
+ compare () { cmp "$@"; }
+fi
+
+DIR='RashuBug'
+# Name of the CMD to execute: the file name must be 6 characters long
+# (to trigger the bug in combination with the test files).
+CMD='tstcmd'
+
+# Create test files.
+make_test_data() {
+ # Create the CMD script and check that it works.
+ mkdir "$DIR" 'bin' \
+ && echo 'printf "%s\n" "$@"' > "bin/$CMD" \
+ && chmod +x "bin/$CMD" \
+ && PATH="$PWD/bin:$PATH" \
+ && [ $( "${ftsfind}" bin -maxdepth 0 -exec "$CMD" '{}' + ) = 'bin' ] \
+ || return 1
+
+ # Create expected output file - also used for creating the test data.
+ { seq -f "${DIR}/abcdefghijklmnopqrstuv%04g" 901 &&
+ seq -f "${DIR}/abcdefghijklmnopqrstu%04g" 902 3719
+ } > exp2 \
+ && LC_ALL=C sort exp2 > exp \
+ && rm exp2 \
+ || return 1
+
+ # Create test files, and check if test data has been created correctly.
+ xargs touch < exp \
+ && [ -f "${DIR}/abcdefghijklmnopqrstu3719" ] \
+ && [ 3719 = $( "${ftsfind}" "$DIR" -type f | wc -l ) ] \
+ || return 1
+}
+
+set -x
+tmpdir="$(mktemp -d)" \
+ && cd "$tmpdir" \
+ && make_test_data "${tmpdir}" \
+ || die "FAIL: failed to set up the test in ${tmpdir}"
+
+fail=0
+for exe in "${ftsfind}" "${oldfind}"; do
+ "$exe" "$DIR" -type f -exec "$CMD" '{}' + > out || fail=1
+ LC_ALL=C sort out > out2 || fail=1
+ compare exp out2 || fail=1
+done
+
+cd ..
+rm -rf "${tmpdir}" || exit 1
+exit $fail
diff --git a/lib/buildcmd.c b/lib/buildcmd.c
index a58f67e..27e9ce5 100644
--- a/lib/buildcmd.c
+++ b/lib/buildcmd.c
@@ -357,11 +357,6 @@ bc_push_arg (struct buildcmd_control *ctl,
assert (arg != NULL);
- if (!initial_args)
- {
- state->todo = 1;
- }
-
if (!terminate)
{
if (state->cmd_argv_chars + len + pfxlen > ctl->arg_max)
@@ -381,6 +376,11 @@ bc_push_arg (struct buildcmd_control *ctl,
bc_do_exec (ctl, state);
}
+ if (!initial_args)
+ {
+ state->todo = 1;
+ }
+
if (state->cmd_argc >= state->cmd_argv_alloc)
{
/* XXX: we could use extendbuf() here. */
--
2.5.5

View File

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

View File

@ -1,7 +1,7 @@
Summary: The GNU versions of find utilities (find and xargs)
Name: findutils
Version: 4.5.16
Release: 1%{?dist}
Release: 4%{?dist}
Epoch: 1
License: GPLv3+
Group: Applications/File
@ -18,9 +18,15 @@ Patch3: findutils-4.4.2-xautofs.patch
# eliminate compile-time warnings
Patch4: findutils-4.5.13-warnings.patch
# make sure that find -exec + passes all arguments (upstream bug #48030)
Patch6: findutils-4.6.0-exec-args.patch
# implement the -noleaf option of find (#1252549)
Patch8: findutils-4.5.15-leaf-opt.patch
# avoid SIGSEGV in case the internal -noop option is used (#1346471)
Patch9: findutils-4.6.0-internal-noop.patch
Requires(post): /sbin/install-info
Requires(preun): /sbin/install-info
Conflicts: filesystem < 3
@ -50,8 +56,15 @@ rm -rf locate
%patch1 -p1
%patch3 -p1
%patch4 -p1
%patch6 -p1
chmod 0755 "find/testsuite/sv-48030-exec-plus-bug.sh"
%patch8 -p1
%patch9 -p1
chmod 0755 "find/testsuite/sv-48180-refuse-noop.sh"
# needed because of findutils-4.4.0-no-locate.patch
autoreconf -fiv
@ -99,6 +112,15 @@ fi
%{_infodir}/find-maint.info.gz
%changelog
* Fri Jun 24 2016 Kamil Dudka <kdudka@redhat.com> - 1:4.5.16-4
- disable leaf optimization for NFS (#1299169)
* Fri Jun 17 2016 Kamil Dudka <kdudka@redhat.com> - 1:4.5.16-3
- avoid SIGSEGV in case the internal -noop option is used (#1346471)
* Tue May 31 2016 Kamil Dudka <kdudka@redhat.com> - 1:4.5.16-2
- make sure that find -exec + passes all arguments (upstream bug #48030)
* Fri Dec 25 2015 Kamil Dudka <kdudka@redhat.com> - 1:4.5.16-1
- new upstream release