public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r14-9888] libstdc++: Handle EMLINK and EFTYPE in std::filesystem::remove_all
Date: Wed, 10 Apr 2024 15:23:59 +0000 (GMT)	[thread overview]
Message-ID: <20240410152359.6E4C83858428@sourceware.org> (raw)

https://gcc.gnu.org/g:9586d6248e89c6bc138f65ea1992de3a2f54a522

commit r14-9888-g9586d6248e89c6bc138f65ea1992de3a2f54a522
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Apr 8 17:41:00 2024 +0100

    libstdc++: Handle EMLINK and EFTYPE in std::filesystem::remove_all
    
    Although POSIX requires ELOOP, FreeBSD documents that openat with
    O_NOFOLLOW returns EMLINK if the last component of a filename is a
    symbolic link.  Check for EMLINK as well as ELOOP, so that the TOCTTOU
    mitigation in remove_all works correctly.
    
    See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=214633 or the
    FreeBSD man page for reference.
    
    According to its man page, DragonFlyBSD also uses EMLINK for this error,
    and NetBSD uses its own EFTYPE. OpenBSD follows POSIX and uses EMLINK.
    
    This fixes these failures on FreeBSD:
    FAIL: 27_io/filesystem/operations/remove_all.cc  -std=gnu++17 execution test
    FAIL: experimental/filesystem/operations/remove_all.cc  -std=gnu++17 execution test
    
    libstdc++-v3/ChangeLog:
    
            * src/c++17/fs_ops.cc (remove_all) [__FreeBSD__ || __DragonFly__]:
            Check for EMLINK as well as ELOOP.
            [__NetBSD__]: Check for EFTYPE as well as ELOOP.

Diff:
---
 libstdc++-v3/src/c++17/fs_ops.cc | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc
index 61df19753ef..07bc2a0fa88 100644
--- a/libstdc++-v3/src/c++17/fs_ops.cc
+++ b/libstdc++-v3/src/c++17/fs_ops.cc
@@ -1312,7 +1312,13 @@ fs::remove_all(const path& p)
     // Our work here is done.
     return 0;
   case ENOTDIR:
-  case ELOOP:
+  case ELOOP:  // POSIX says openat with O_NOFOLLOW sets ELOOP for a symlink.
+#if defined __FreeBSD__ || defined __DragonFly__
+  case EMLINK: // Used instead of ELOOP
+#endif
+#if defined __NetBSD__ && defined EFTYPE
+  case EFTYPE: // Used instead of ELOOP
+#endif
     // Not a directory, will remove below.
     break;
 #endif
@@ -1352,7 +1358,13 @@ fs::remove_all(const path& p, error_code& ec)
     ec.clear();
     return 0;
   case ENOTDIR:
-  case ELOOP:
+  case ELOOP:  // POSIX says openat with O_NOFOLLOW sets ELOOP for a symlink.
+#if defined __FreeBSD__ || defined __DragonFly__
+  case EMLINK: // Used instead of ELOOP
+#endif
+#if defined __NetBSD__ && defined EFTYPE
+  case EFTYPE: // Used instead of ELOOP
+#endif
     // Not a directory, will remove below.
     break;
 #endif

                 reply	other threads:[~2024-04-10 15:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240410152359.6E4C83858428@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).