Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: files module improvements



Zoltan Hidvegi wrote:
>If chdir("..") succeeds it always go back where you started so it is as
>safe to use as fchdir.

Not true.  If a directory is moved, its .. changes.  One of the attacks
on /tmp-clearing cron jobs that has been proposed goes like

mkdir -p /tmp/a/b
# make large directory tree under /tmp/a/b
# wait for the cron job to start deleting under /tmp/a/b
mv /tmp/a/b /tmp/b

and when the rm does chdir("..") from b, thinking it is going back to
/tmp/a, it is actually entering /tmp.  It then does another
chdir(".."), trying to get back to /tmp, and actually enters /.

This attack can be detected (but not prevented entirely) by doing
stat(".") before entering a subdirectory, and after leaving it.  If the
two do not match, then the directory was moved while being cleared, and
the current directory could be pretty much anything -- rm would have to
abort.

-zefram



Messages sorted by: Reverse Date, Date, Thread, Author