Commit Graph

68 Commits

Author SHA1 Message Date
Andrey Semashev
36cf9aaf81 Updated protection of remove_all against CVE-2022-21658 on POSIX.
The previous implementation could still allow for following symlinks
while remove_all is running if a directory was replaced with a symlink
higher in the tree than remove_all is currently processing. This was
reported here:

https://github.com/boostorg/filesystem/issues/224#issuecomment-1183738097

The solution is to use POSIX.1-2008 *at APIs to prevent symlink resolution
higher in the directory tree while iterating over the subtree in remove_all.
This required updating the directory iterator construction interface so that
it is possible to pass the base directory fd and return fd of the directory
used by the iterator. This is done via platform-specific params that are
currently defined only for POSIX. Additionally, status, symlink_status and
remove were extended to accept the base directory fd as well.

Other systems, including Windows, remain vulnerable.

Related to https://github.com/boostorg/filesystem/issues/224.
2022-07-17 04:00:07 +03:00
Andrey Semashev
41d076ace5 Added protection for CVE-2022-21658 in remove_all on POSIX systems.
Another process could replace the directory being processed by remove_all
with a symlink after remove_all called symlink_status but before
it creates a directory iterator. As a result, remove_all would remove
the linked directory contents instead of removing the symlink.

On POSIX systems that support fdopendir and O_NOFOLLOW flag for open(2),
this can be prevented by opening the directory with O_NOFOLLOW before
iterating. This will fail if the directory was replaced with a symlink.

No protection on other systems.

Reported in https://github.com/boostorg/filesystem/issues/224.
2022-01-30 23:41:06 +03:00
Andrey Semashev
54ea0cc2f1 Added macro definitions to disable deprecated CRT warnings on Windows. 2021-10-26 19:03:28 +03:00
Andrey Semashev
9e5a3e231e Added a configure check for init_priority attribute.
Apparently, gcc does not support the attribute on Mac OS 11.4. Since
we can't tell if other systems aren't supported as well, it's better
to check with a configure check. As a side effect, this might add
support for more compilers.

Closes https://github.com/boostorg/filesystem/issues/199.
2021-07-14 18:12:47 +03:00
Andrey Semashev
2dda038306 Reworked function pointers use and definitions.
Instead of using atomic<> to access global function pointers, use raw
pointers and atomic_ref to access them safely in multi-threaded builds.
This allows to ensure constant initialization of the function pointers,
even in C++03. This also solves the problem of undefined dynamic
initialization order that we previously tried to solve with the
init_priority attribute. The attribute turns out to not work if the
pointers were raw pointers (in single-threaded builds). It is also
not supported by Intel Compiler and possibly other, which required
us to avoid using the function pointer for fill_random.

The resulting code should be simpler and more portable. In order to
check for C++20 std::atomic_ref availability, the older check for <atomic>
header was replaced with a check for std::atomic_ref. If not available,
we're using Boost.Atomic, as before.
2021-06-14 22:09:15 +03:00
Andrey Semashev
45682f8501 Only build windows_file_codecvt on Windows and Cygwin. 2021-06-11 15:11:43 +03:00
Andrey Semashev
98daa68aa8 Force use of windows.h when building the library.
This forces definition of _WIN32_WINNT by Boost.WinAPI, which is important
for CopyFileEx and related symbols to be defined. Platform SDK from MSVC-8
does not define the macro by default, which caused compilation errors
previously.
2021-05-21 00:09:00 +03:00
Andrey Semashev
0bbc79b884 Remove Boost.Atomic dependency in single-threaded builds.
In single-threaded builds we can assume no thread synchronization
is necessary and avoid the dependency on Boost.Atomic. The dependency
caused single-threaded build failures because Boost.Atomic requires
multithreading to be enabled.

The CMake build currently does not support single-threaded builds, so
the dependency is left present there.

Closes https://github.com/boostorg/filesystem/issues/188.
2021-05-20 02:35:34 +03:00
Andrey Semashev
b27ad65326 Increased the minimum buffer size in read/write loop in copy_file.
Also, take into account the target filesystem block size, if available.
2021-05-19 00:22:31 +03:00
Andrey Semashev
4b9052f1e0 Fallback to read/write loop if sendfile/copy_file_range fail.
Since sendfile and copy_file_range can fail for some filesystems
(e.g. eCryptFS), we have to fallback to the read/write loop in copy_file
implementation. Additionally, since we implement the fallback now,
fallback to sendfile if copy_file_range fails with EXDEV and use
copy_file_range on older kernels that don't implement it for
cross-filesystem copying. This may be beneficial if copy_file_range
is used within a filesystem, and is performed on a remote server NFS or CIFS).

Also, it was discovered that copy_file_range can also fail with EOPNOTSUPP
when it is performed on an NFSv4 filesystem and the remote server does
not support COPY operation. This happens on some patched kernels in RHEL/CentOS.

Lastly, to make sure the copy_file_data pointer is accessed atomically,
it is now declared as an atomic value. If std::atomic is unavailable,
Boost.Atomic is used.

Fixes https://github.com/boostorg/filesystem/issues/184.
2021-05-18 23:16:02 +03:00
Andrey Semashev
05de74a000 Added config macros for disabling use of some system APIs.
By defining these new config macros the user can configure the library
to avoid using some system APIs even if they are detected as available
by the library build scripts. This can be useful in case if the API
is known to consistently fail at runtime on the target system.

Related to https://github.com/boostorg/filesystem/issues/172.
2021-05-16 20:44:09 +03:00
Andrey Semashev
a031e4ffa9 Added creation_time operation.
The operation allows to query file creation time.

Implementation partially inspired by:

https://github.com/boostorg/filesystem/pull/134

Closes https://github.com/boostorg/filesystem/pull/134.
2020-08-21 01:32:04 +03:00
Andrey Semashev
db390391bb Restored auto-linking and Windows CE support.
Auto-linking can still be useful to users of MSVC and compatible
compilers on Windows, when the user links against static build of
Boost.Filesystem. This feature is marked deprecated though, so
it can be removed in the future, when the generated CMake config
files include information about third-party dependencies of Boost
libraries.

Additionally, restored support for linking against Windows CE-cpecific
coredll library. This platform is not tested though and therefore not
properly supported.

Closes https://github.com/boostorg/filesystem/issues/156.
2020-07-28 14:48:42 +03:00
Andrey Semashev
1104092053 Extracted platform defines to a separate header and include it everywhere.
This should fix readdir(_r) on 32-bit systems, which was not 64-bit after
commit c758552338 because _FILE_OFFSET_BITS=64
was not defined in directory.cpp. Also, there were filesystem-related system
calls in unique_path.cpp, where the macro was not defined either. Including
the platform header in all source files is useful for possible future changes
that may require the platform-specific macros.

Closes https://github.com/boostorg/filesystem/pull/150.
2020-07-02 13:37:45 +03:00
Andrey Semashev
43dfdc6ac9 Marked bcrypt and advapi32 libs explicit. 2020-06-08 00:35:30 +03:00
Andrey Semashev
49f12dd890 Moved Windows SDK library declarations out of the crypro API selection rule.
This should fix Boost.Build error on Windows.
2020-06-05 13:07:20 +03:00
Andrey Semashev
e75b455a0f Select Windows crypto API on Cygwin as well. 2020-06-05 12:06:15 +03:00
Andrey Semashev
5d1b14df51 Moved Windows lib linking to the Jamfile and added a config check for BCrypt.
This should improve support for Windows compilers that don't support
auto-linking.
2020-06-05 11:58:17 +03:00
Andrey Semashev
9252269160 Added configuration steps to detect modification time representation in stat.
This should improve compatibility with Mac OS X and other systems with
various representations of file times in struct stat.
2020-05-12 14:56:24 +03:00
Andrey Semashev
c758552338 Moved directory tools to separate files. Reworked readdir_r support.
Directory iteration components were moved to separate files to simplify
maintenance of operations.hpp/cpp.

directory_iterator implementation on POSIX platforms has been reworked
to only allocate internal buffer when readdir_r is used. When readdir
is used, the dirent structure returned by readdir is used directly, which
eliminates the potential of buffer overrun in case if some directory name
exceeds the buffer size. This also removes the need to copy dirent members
into the buffer, which improves performance and simplifies maintenance.

For buffer size we now use the max path size as opposed to max filename
size. This is done to minimize the possibility of buffer overruns when
readdir_r is used.

On Windows, use Boost.WinAPI to configure the default target Windows version.
This removes WINVER and _WIN32_WINNT defines in Boost.Filesystem as these
macros should be defined by Boost.WinAPI now.

Additionally, exception.hpp and directory.hpp includes in operations.hpp are
marked as deprecated as operations.hpp do not need those components. Users
are encouraged to include the new headers explicitly in their code, as needed.
2019-08-01 20:34:39 +03:00
Andrey Semashev
f4769bd4c7 Extracted file_status and error handling helpers to separate headers.
This simplifies maintenance of the operations.hpp/cpp files.

Also, moved BOOST_FILESYSTEM_SOURCE definition to the build system files
instead of defining it in every source file.
2019-07-31 23:12:56 +03:00
Andrey Semashev
68ec5b1fb6 Extracted filesystem_error to a separate header and translation unit.
This simplifies maintenance of the operations.hpp header and should also
reduce size of the generated users' code.
2019-07-31 22:58:40 +03:00
Andrey Semashev
2c1fa1a4a0 Removed linking with Boost.System.
Since Boost.System is now header-only, no need to depend on its library.

Fixes https://github.com/boostorg/filesystem/issues/98.
2019-01-14 20:08:41 +03:00
Andrey Semashev
1cfaf4839d Converted tabs to spaces in the Jamfile. 2018-11-24 21:26:14 +03:00
Beman Dawes
c4d3e3d64c For HP-UX/GCC only, define _INCLUDE_STDC__SOURCE_199901 as a build requirement. Fix #5048.
[SVN r83443]
2013-03-15 18:10:48 +00:00
Beman Dawes
03195bfb17 Tighten config.hpp and Jamfile logic before attaching static build problems.
[SVN r77997]
2012-04-15 19:16:49 +00:00
Beman Dawes
7941871477 Filesystem - Delete v3 directories no longer needed. Cleanup links, namespaces, and other residue from dual v2/v3 support.
[SVN r77555]
2012-03-26 12:44:24 +00:00
Beman Dawes
16099b4c7d Filesystem - Move V3 files and directories into place
[SVN r77554]
2012-03-26 12:31:06 +00:00
Beman Dawes
883ba9b788 Filesystem - delete v2 directories, forwarding files.
[SVN r77553]
2012-03-26 12:27:17 +00:00
Beman Dawes
c1ca110b6f Resolve ticket #4585 by accepting bjam options --disable-filesystem2 or --disable-filesystem3. Document same. Also, switch V2 tests to use <boost/detail/lightweight_main.hpp> to improved test reporting.
[SVN r67078]
2010-12-07 00:57:13 +00:00
Beman Dawes
7922c919d8 V2 tests added. All tests passing on at least one compiler, none passing on all compilers
[SVN r62759]
2010-06-10 20:02:39 +00:00
Beman Dawes
98d00b2e88 Add Build and Test support. Build is working, a few tests are working.
[SVN r62662]
2010-06-09 15:07:03 +00:00
Beman Dawes
3b51e980ae Initial source code changes to achieve integration
[SVN r62659]
2010-06-09 14:05:57 +00:00
Beman Dawes
fa515c07f5 Move files into new v2 + v3 directory structure
[SVN r62653]
2010-06-09 13:00:15 +00:00
Beman Dawes
193583fe1f Apply fix #4237 uniformly to all shared builds, in the hope that this same problem is what is causing failures on IBM and Sun platforms. Believed to be harmless on platforms where it isn't needed.
[SVN r62179]
2010-05-24 19:26:26 +00:00
Christopher Jefferson
4595081faf Explicitally link boost_system in boost_filesystem on darwin, the same as windows
[SVN r62121]
2010-05-21 16:55:54 +00:00
Vladimir Prus
f8d0a92eed Don't set *_STATIC_LINK macros, for they don't affect anything.
[SVN r59197]
2010-01-21 16:19:28 +00:00
Beman Dawes
eae84be7c0 Fix typo
[SVN r58235]
2009-12-08 12:44:14 +00:00
Vladimir Prus
121ad129f0 Fix Boost.Filesystem->Boost.System dependency for windows/shared.
[SVN r58028]
2009-11-29 10:03:34 +00:00
Rene Rivera
9f4db62f67 Remove redundant reference to system library. It causes double linking when used indirectly through filesystem. Which can lead to double linking incompatible variants when a specific filesystem variant is requested.
[SVN r41118]
2007-11-15 22:05:15 +00:00
Vladimir Prus
5bc47254c6 Make sure every library can be installed by using
bjam stage|install

in libs/<library>/build.


[SVN r40475]
2007-10-26 09:04:25 +00:00
Rene Rivera
e236cd76f7 Add usage dependency on system library.
[SVN r40021]
2007-10-14 17:54:28 +00:00
Beman Dawes
092e3ce2fb Add usage-requirements. See comment in file.
[SVN r39254]
2007-09-14 01:58:20 +00:00
Beman Dawes
49f6e3cfd7 Merge system and filesystem branches, bringing them in sync with N2415. Several filesystem bugs fixed, and current_path setter added.
[SVN r39173]
2007-09-09 14:59:10 +00:00
Vladimir Prus
c1840ee23f Remove V1 Jamfiles
[SVN r38516]
2007-08-08 19:02:26 +00:00
Rene Rivera
14f0535f27 Fix missing sysbols on linking as the reference to boost_system needs to be specific.
[SVN r36219]
2006-12-01 00:46:22 +00:00
Beman Dawes
e7b1456dee v1 and v2 Jamfiles now present and working
[SVN r35890]
2006-11-07 02:20:47 +00:00
Beman Dawes
2045be22d6 Bring into compliance with N2066, TR2 Diagnostics Enhancements. Tests passing on Win32, Linux, on most modern compilers.
[SVN r35823]
2006-11-03 16:57:30 +00:00
Douglas Gregor
9e13c0973c Bring in sync with BBv1 Jamfile
[SVN r32093]
2005-12-18 18:09:12 +00:00
Beman Dawes
48d4335bfc merge from i18n branch - at last!
[SVN r32079]
2005-12-16 16:40:35 +00:00