mirror of
https://github.com/boostorg/filesystem.git
synced 2026-02-23 03:32:18 +00:00
Fix #12495, create_directories() crashes when passed empty string as path, from Samantha Ritter. Also affected create_directory(). Charles Olivi submitted a pull request with some particularly helpful test cases.
This commit is contained in:
@@ -937,6 +937,17 @@ namespace detail
|
||||
BOOST_FILESYSTEM_DECL
|
||||
bool create_directories(const path& p, system::error_code* ec)
|
||||
{
|
||||
if (p.empty())
|
||||
{
|
||||
if (ec == 0)
|
||||
BOOST_FILESYSTEM_THROW(filesystem_error(
|
||||
"boost::filesystem::create_directories", p,
|
||||
system::errc::make_error_code(system::errc::invalid_argument)));
|
||||
else
|
||||
ec->assign(system::errc::invalid_argument, system::generic_category());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (p.filename_is_dot() || p.filename_is_dot_dot())
|
||||
return create_directories(p.parent_path(), ec);
|
||||
|
||||
@@ -990,7 +1001,8 @@ namespace detail
|
||||
// attempt to create directory failed
|
||||
int errval(BOOST_ERRNO); // save reason for failure
|
||||
error_code dummy;
|
||||
if (errval == BOOST_ERROR_ALREADY_EXISTS && is_directory(p, dummy))
|
||||
|
||||
if (is_directory(p, dummy))
|
||||
{
|
||||
if (ec != 0)
|
||||
ec->clear();
|
||||
@@ -1003,6 +1015,7 @@ namespace detail
|
||||
p, error_code(errval, system_category())));
|
||||
else
|
||||
ec->assign(errval, system_category());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user