find: do not silently disable -L when -delete is used
First of all, current behavior is not documented and confusing, and it can be very dangerous in the following sequence: find -L . -type l find -L . -type l -delete (the second line is even suggested by find(1)). Instead simply refuse to proceed when -L and -delete are both used. A descriptive error message is provided. The following command can be safely used to remove broken links: find -L . -type l -print0 | xargs rm -0 To do: update find(1) PR: bin/90687 Obtained from: Anatoli Klassen <anatoli@aksoft.net> Approved by: jhb (mentor)
This commit is contained in:
parent
51ca6cd6df
commit
05e605b764
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=192381
@ -427,11 +427,13 @@ f_delete(PLAN *plan __unused, FTSENT *entry)
|
||||
|
||||
/* sanity check */
|
||||
if (isdepth == 0 || /* depth off */
|
||||
(ftsoptions & FTS_NOSTAT) || /* not stat()ing */
|
||||
!(ftsoptions & FTS_PHYSICAL) || /* physical off */
|
||||
(ftsoptions & FTS_LOGICAL)) /* or finally, logical on */
|
||||
(ftsoptions & FTS_NOSTAT)) /* not stat()ing */
|
||||
errx(1, "-delete: insecure options got turned on");
|
||||
|
||||
if (!(ftsoptions & FTS_PHYSICAL) || /* physical off */
|
||||
(ftsoptions & FTS_LOGICAL)) /* or finally, logical on */
|
||||
errx(1, "-delete: forbidden when symlinks are followed");
|
||||
|
||||
/* Potentially unsafe - do not accept relative paths whatsoever */
|
||||
if (strchr(entry->fts_accpath, '/') != NULL)
|
||||
errx(1, "-delete: %s: relative path potentially not safe",
|
||||
@ -462,8 +464,6 @@ c_delete(OPTION *option, char ***argvp __unused)
|
||||
{
|
||||
|
||||
ftsoptions &= ~FTS_NOSTAT; /* no optimise */
|
||||
ftsoptions |= FTS_PHYSICAL; /* disable -follow */
|
||||
ftsoptions &= ~FTS_LOGICAL; /* disable -follow */
|
||||
isoutput = 1; /* possible output */
|
||||
isdepth = 1; /* -depth implied */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user