[libcxx-commits] [PATCH] D97618: [libcxx] Avoid infinite recursion in create_directories, if the root directory doesn't exist
Martin Storsjö via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Feb 27 14:48:40 PST 2021
mstorsjo created this revision.
mstorsjo added a reviewer: libc++.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added 1 blocking reviewer(s): libc++.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97618
Files:
libcxx/src/filesystem/operations.cpp
libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp
Index: libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp
===================================================================
--- libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp
+++ libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp
@@ -138,4 +138,18 @@
TEST_CHECK(!exists(dir));
}
+#ifdef _WIN32
+TEST_CASE(nonexistent_root)
+{
+ std::error_code ec = GetTestEC();
+ // If Q:\ doesn't exist, create_directories would try to recurse upwards
+ // to parent_path() until it finds a directory that does exist. As the
+ // whole path is the root name, parent_path() returns itself, and it
+ // would recurse indefinitely, unless the recursion is broken.
+ if (!exists("Q:\\"))
+ TEST_CHECK(fs::create_directories("Q:\\", ec) == false);
+ TEST_CHECK(fs::create_directories("\\\\nonexistentserver", ec) == false);
+}
+#endif
+
TEST_SUITE_END()
Index: libcxx/src/filesystem/operations.cpp
===================================================================
--- libcxx/src/filesystem/operations.cpp
+++ libcxx/src/filesystem/operations.cpp
@@ -1021,6 +1021,8 @@
if (not status_known(parent_st))
return err.report(m_ec);
if (not exists(parent_st)) {
+ if (parent == p)
+ return err.report(errc::invalid_argument);
__create_directories(parent, ec);
if (ec && *ec) {
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97618.326930.patch
Type: text/x-patch
Size: 1525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210227/c6873203/attachment.bin>
More information about the libcxx-commits
mailing list