aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-01-09 16:07:11 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-01-09 16:08:09 +0100
commit6eb0cbe07e5c2f3131c2d6a5bafd83d2cac20f7d (patch)
treea1fcb5d74314262e2d2df51d20411e5a25f6a7ed
parentf0058b1b1fe9f7e69b415616096fb9347f599426 (diff)
downloadbusybox-w32-6eb0cbe07e5c2f3131c2d6a5bafd83d2cac20f7d.tar.gz
busybox-w32-6eb0cbe07e5c2f3131c2d6a5bafd83d2cac20f7d.tar.bz2
busybox-w32-6eb0cbe07e5c2f3131c2d6a5bafd83d2cac20f7d.zip
find: fix a regression introduced with -HLP support
function old new delta find_main 294 342 +48 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/find.c21
-rwxr-xr-xtestsuite/find.tests22
2 files changed, 42 insertions, 1 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 53d8239c7..5d5e24bfb 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -1291,9 +1291,27 @@ int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1291int find_main(int argc UNUSED_PARAM, char **argv) 1291int find_main(int argc UNUSED_PARAM, char **argv)
1292{ 1292{
1293 int i, firstopt, status = EXIT_SUCCESS; 1293 int i, firstopt, status = EXIT_SUCCESS;
1294 char **past_HLP, *saved;
1294 1295
1295 INIT_G(); 1296 INIT_G();
1296 1297
1298 /* "find -type f" + getopt("+HLP") => disaster.
1299 * Need to avoid getopt running into a non-HLP option.
1300 * Do this by temporarily storing NULL there:
1301 */
1302 past_HLP = argv;
1303 for (;;) {
1304 saved = *++past_HLP;
1305 if (!saved)
1306 break;
1307 if (saved[0] != '-')
1308 break;
1309 if (!saved[1])
1310 break; /* it is "-" */
1311 if ((saved+1)[strspn(saved+1, "HLP")] != '\0')
1312 break;
1313 }
1314 *past_HLP = NULL;
1297 /* "+": stop on first non-option */ 1315 /* "+": stop on first non-option */
1298 i = getopt32(argv, "+HLP"); 1316 i = getopt32(argv, "+HLP");
1299 if (i & (1<<0)) 1317 if (i & (1<<0))
@@ -1301,7 +1319,8 @@ int find_main(int argc UNUSED_PARAM, char **argv)
1301 if (i & (1<<1)) 1319 if (i & (1<<1))
1302 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK; 1320 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
1303 /* -P is default and is ignored */ 1321 /* -P is default and is ignored */
1304 argv += optind; 1322 argv = past_HLP; /* same result as "argv += optind;" */
1323 *past_HLP = saved;
1305 1324
1306 for (firstopt = 0; argv[firstopt]; firstopt++) { 1325 for (firstopt = 0; argv[firstopt]; firstopt++) {
1307 if (argv[firstopt][0] == '-') 1326 if (argv[firstopt][0] == '-')
diff --git a/testsuite/find.tests b/testsuite/find.tests
new file mode 100755
index 000000000..345d1e82e
--- /dev/null
+++ b/testsuite/find.tests
@@ -0,0 +1,22 @@
1#!/bin/sh
2
3# Copyright 2014 by Denys Vlasenko <vda.linux@googlemail.com>
4# Licensed under GPLv2, see file LICENSE in this source tree.
5
6. ./testing.sh
7
8# testing "description" "command" "result" "infile" "stdin"
9
10mkdir -p find.tempdir
11touch find.tempdir/testfile
12
13testing "find -type f" \
14 "cd find.tempdir && find -type f 2>&1" \
15 "./testfile\n" \
16 "" ""
17
18# testing "description" "command" "result" "infile" "stdin"
19
20rm -rf find.tempdir
21
22exit $FAILCOUNT