[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
Fri Mar 5 00:49:26 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG99c7b5329465: [libcxx] Avoid infinite recursion in create_directories, if the root directory… (authored by mstorsjo).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97618/new/

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
@@ -1019,6 +1019,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.328421.patch
Type: text/x-patch
Size: 1525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210305/970cd933/attachment.bin>


More information about the libcxx-commits mailing list