>From 595060f28eb5f658fa8d98970959c617fab0f078 Mon Sep 17 00:00:00 2001 From: Bernhard Voelker
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 in https://savannah.gnu.org/bugs/?48180 --- NEWS | 3 + find/parser.c | 6 +- find/testsuite/Makefile.am | 3 +- find/testsuite/sv-48180-refuse-noop.sh | 117 +++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100755 find/testsuite/sv-48180-refuse-noop.sh diff --git a/NEWS b/NEWS index 2070f0e..facd336 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,9 @@ of the - yet more portable - '( -type l -o -type d )'. ** Bug Fixes +#48180: find -noop (an internal option not intended to be exposed to the user) + no longer crashes. Bug introduced in FINDUTILS-4.3.1. + #48030: find -exec + does not pass all arguments for certain specific filename lengths. After the internal (usually 128k) buffer is full and find(1) executed the given command with these arguments, it would miss to run diff --git a/find/parser.c b/find/parser.c index 5777133..3ed5c31 100644 --- a/find/parser.c +++ b/find/parser.c @@ -323,7 +323,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 */ @@ -599,6 +600,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 cb34830..0fcd842 100644 --- a/find/testsuite/Makefile.am +++ b/find/testsuite/Makefile.am @@ -260,7 +260,8 @@ test_inode.sh \ test_type-list.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