Sat 14 Apr 2007 02:50:52 PM UTC, comment #4:
I attach a patch which switches ftsfind.c to using FTS_CWDFD. Unfortunately, this involved many changes in all sorts of places, since many filesystem operations (such as readlink() and access()) have no *at() equivalent.
The patch should apply against the current findutils CVS code (against HEAD, which is currently the findutils-4.3.x development code).
I haven't decided yet whether or not to go this way.
(file #12480)
|
Wed 06 Dec 2006 05:04:31 AM UTC, comment #1:
This patch is a quick hack; it won't work on systems like mingw that lack fchdir (although this is not much of a loss, since gnulib's fts currently requires fchdir, and will be resolved once someone contributes a gnulib fchdir module), or where . cannot be returned to (also not much of a loss, since without FTS_CWDFD, you are already performing chdirs, so it is only extreme race cases that can cause problems, and this is not adding to the vulnerability). Since it is a hack, I did not bother checking for failure; all the more reason to not accept this patch as-is. But with this hack applied, the testcase mentioned in the original report uses the correct directory.
IMO, a better solution would be to use gnulib's FTS_CWDFD so that the traversal never changes working directories, then do fchdir inside launch(), after the fork but before the exec. But converting ftsfind to use FTS_CWDFD seemed like a more time-consuming project, not to mention that all callers of launch would need a change to pass the target working directory fd.
2006-12-05 Eric Blake <ebb9@byu.net>
Hack - use at your own risk:
- find/ftsfind.c (consider_visiting): Save and restore
directories, so that -execdir runs in the correct location.
(file #11460)
|
Wed 06 Dec 2006 04:29:05 AM UTC, original submission:
The change from oldfind to the fts algorithm broke -execdir {} +:
http://cygwin.com/ml/cygwin/2006-12/msg00203.html
The command is being run in the parent directory rather than the directory that provided the current set of {} argument expansions.
I'm not sure of the fix off hand, but it seems like leaving a directory is the trigger to run the command on the collected arguments, but it triggers after the working dir has already been changed. You either need to trigger sooner, or temporarily revert the working directory back to where the arguments were collected.
|