fts: Use O_DIRECTORY when opening name that might be changed by attacker.

There are uncommon cases where fts_safe_changedir() may be called with a
non-NULL name that is not "..". Do not block or worse if an attacker put (a
(symlink to) a fifo or device where a directory used to be.

MFC after:	1 week


git-svn-id: svn+ssh://svn.freebsd.org/base/head@246641 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
This commit is contained in:
jilles committed 2013-02-10 23:09:15 +00:00
1 parent 746e181156
commit f9928f1705
1 file changed
+2 -1
+2 -1
View File
@@ -1119,7 +1119,8 @@ fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)
newfd = fd;
if (ISSET(FTS_NOCHDIR))
return (0);
if (fd < 0 && (newfd = _open(path, O_RDONLY | O_CLOEXEC, 0)) < 0)
if (fd < 0 && (newfd = _open(path, O_RDONLY | O_DIRECTORY |
O_CLOEXEC, 0)) < 0)
return (-1);
if (_fstat(newfd, &sb)) {
ret = -1;