[Boost-bugs] [Boost C++ Libraries] #13028: boost::filesystem::canonical(const path& p, system::error_code& ec) throws exception

Subject: [Boost-bugs] [Boost C++ Libraries] #13028: boost::filesystem::canonical(const path& p, system::error_code& ec) throws exception
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-05-12 20:18:22


#13028: boost::filesystem::canonical(const path& p, system::error_code& ec) throws
exception
---------------------------------------------+------------------------
 Reporter: Zach Wasserman <zachwass2000@…> | Owner: bemandawes
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: filesystem
  Version: Boost 1.65.0 | Severity: Problem
 Keywords: |
---------------------------------------------+------------------------
 Per
 [http://www.boost.org/doc/libs/1_64_0/libs/filesystem/doc/reference.html
 #Error-reporting the docs], this function should report filesystem errors
 through the error_code. In the case of permission issues, this contract is
 violated.

 This is best explained with the test case:

 {{{
 #include <boost/detail/lightweight_test_report.hpp>
 #include <boost/filesystem.hpp>

 namespace fs = boost::filesystem;

 int test_main(int, char*[])
 {
   // Ensure that we do not have read permissions on pwd
   fs::path tmp_path = fs::temp_directory_path();
   fs::path unique_path = fs::unique_path();
   fs::path dir_path = tmp_path / unique_path;
   fs::create_directory(dir_path);
   fs::current_path(dir_path);
   fs::permissions(dir_path, fs::no_perms);

   // Try to get a canonical path with the error_code API. This should
 return an
   // error through the error_code, but instead throws an exception
 (because
   // canonical(const path& p, system::error_code& ec) calls current_path()
   // without error_code)
   boost::system::error_code e;
   fs::canonical("foo", e);
   BOOST_TEST(e.value() != 0);

   return ::boost::report_errors();
 }
 }}}

 Test output:

 {{{
 bin/bug
 Clang version 8.0.0 (clang-800.0.38), __GXX_EXPERIMENTAL_CXX0X__ not
 defined
 libc++ version 3700
 Mac OS
 Boost version 1.65.0
 Command line: bin/bug

 ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR
 ERROR

 ****************************** std::exception
 *****************************
 boost::filesystem::current_path: Permission denied
 ***************************************************************************

 }}}

 This unexpected exception causes a crash in osquery. See
 [https://github.com/facebook/osquery/issues/3279]

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/13028>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-05-12 20:21:54 UTC