diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-01-09 16:07:11 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-01-09 16:08:09 +0100 |
commit | 6eb0cbe07e5c2f3131c2d6a5bafd83d2cac20f7d (patch) | |
tree | a1fcb5d74314262e2d2df51d20411e5a25f6a7ed /findutils | |
parent | f0058b1b1fe9f7e69b415616096fb9347f599426 (diff) | |
download | busybox-6eb0cbe07e5c2f3131c2d6a5bafd83d2cac20f7d.tar.gz |
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>
Diffstat (limited to 'findutils')
-rw-r--r-- | findutils/find.c | 21 |
1 files changed, 20 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; int find_main(int argc UNUSED_PARAM, char **argv) { int i, firstopt, status = EXIT_SUCCESS; + char **past_HLP, *saved; INIT_G(); + /* "find -type f" + getopt("+HLP") => disaster. + * Need to avoid getopt running into a non-HLP option. + * Do this by temporarily storing NULL there: + */ + past_HLP = argv; + for (;;) { + saved = *++past_HLP; + if (!saved) + break; + if (saved[0] != '-') + break; + if (!saved[1]) + break; /* it is "-" */ + if ((saved+1)[strspn(saved+1, "HLP")] != '\0') + break; + } + *past_HLP = NULL; /* "+": stop on first non-option */ i = getopt32(argv, "+HLP"); if (i & (1<<0)) @@ -1301,7 +1319,8 @@ int find_main(int argc UNUSED_PARAM, char **argv) if (i & (1<<1)) G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK; /* -P is default and is ignored */ - argv += optind; + argv = past_HLP; /* same result as "argv += optind;" */ + *past_HLP = saved; for (firstopt = 0; argv[firstopt]; firstopt++) { if (argv[firstopt][0] == '-') |