diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-01-23 21:45:16 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-01-25 21:05:15 +0000 |
commit | c8bd4dc8212e43b2f9af08b80df97f90cdb0df4f (patch) | |
tree | 23b7500bdfc19a2ec62157cd271d06a39da098cb /libstdc++-v3/acinclude.m4 | |
parent | ec543c9833c2d9283c035cd8430849eb4ec04406 (diff) | |
download | gcc-c8bd4dc8212e43b2f9af08b80df97f90cdb0df4f.zip gcc-c8bd4dc8212e43b2f9af08b80df97f90cdb0df4f.tar.gz gcc-c8bd4dc8212e43b2f9af08b80df97f90cdb0df4f.tar.bz2 |
libstdc++: Avoid symlink race in filesystem::remove_all [PR104161]
This adds a new internal flag to the filesystem::directory_iterator
constructor that makes it fail if the path is a symlink that resolves to
a directory. This prevents filesystem::remove_all from following a
symlink to a directory, rather than deleting the symlink itself.
We can also use that new flag in recursive_directory_iterator to ensure
that we don't follow symlinks if the follow_directory_symlink option is
not set.
This also moves an error check in filesystem::remove_all after the while
loop, so that errors from the directory_iterator constructor are
reproted, instead of continuing to the filesystem::remove call below.
libstdc++-v3/ChangeLog:
PR libstdc++/104161
* acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for
fdopendir.
* config.h.in: Regenerate.
* configure: Regenerate.
* src/c++17/fs_dir.cc (_Dir): Add nofollow flag to constructor
and pass it to base class constructor.
(directory_iterator): Pass nofollow flag to _Dir constructor.
(fs::recursive_directory_iterator::increment): Likewise.
* src/c++17/fs_ops.cc (do_remove_all): Use nofollow option for
directory_iterator constructor. Move error check outside loop.
* src/filesystem/dir-common.h (_Dir_base): Add nofollow flag to
constructor and when it's set use ::open with O_NOFOLLOW and
O_DIRECTORY.
* src/filesystem/dir.cc (_Dir): Add nofollow flag to constructor
and pass it to base class constructor.
(directory_iterator): Pass nofollow flag to _Dir constructor.
(fs::recursive_directory_iterator::increment): Likewise.
* src/filesystem/ops.cc (remove_all): Use nofollow option for
directory_iterator constructor. Move error check outside loop.
Diffstat (limited to 'libstdc++-v3/acinclude.m4')
-rw-r--r-- | libstdc++-v3/acinclude.m4 | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index d996477..7b6b807 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -4736,6 +4736,18 @@ dnl AC_DEFINE(HAVE_TRUNCATE, 1, [Define if truncate is available in <unistd.h>.]) fi dnl + AC_CACHE_CHECK([for fdopendir], + glibcxx_cv_fdopendir, [dnl + GCC_TRY_COMPILE_OR_LINK( + [#include <dirent.h>], + [::fdopendir(1);], + [glibcxx_cv_fdopendir=yes], + [glibcxx_cv_fdopendir=no]) + ]) + if test $glibcxx_cv_truncate = yes; then + AC_DEFINE(HAVE_FDOPENDIR, 1, [Define if fdopendir is available in <dirent.h>.]) + fi +dnl CXXFLAGS="$ac_save_CXXFLAGS" AC_LANG_RESTORE ]) |