commit 2ae4ec56c2b18c46ef8220bcddac4303a4b6ef1c
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Mon May 12 01:52:51 2025 +0200

    hurd: Make rename refuse trailing slashes [BZ #32570]
    
    As tested by Gnulib's renameatu module.
    
    Reported by Collin Funk on
    https://sourceware.org/bugzilla/show_bug.cgi?id=32570

diff --git a/sysdeps/mach/hurd/renameat2.c b/sysdeps/mach/hurd/renameat2.c
index 59a4e314fc..5b09fedf7f 100644
--- a/sysdeps/mach/hurd/renameat2.c
+++ b/sysdeps/mach/hurd/renameat2.c
@@ -37,15 +37,28 @@ __renameat2 (int oldfd, const char *old, int newfd, const char *new,
   if (flags & RENAME_NOREPLACE)
     excl = 1;
 
-  olddir = __directory_name_split_at (oldfd, old, (char **) &oldname);
+  olddir = __file_name_split_at (oldfd, old, (char **) &oldname);
   if (olddir == MACH_PORT_NULL)
     return -1;
-  newdir = __directory_name_split_at (newfd, new, (char **) &newname);
+  if (!*oldname)
+    {
+      /* Trailing slash.  */
+      __mach_port_deallocate (__mach_task_self (), olddir);
+      return __hurd_fail (ENOTDIR);
+    }
+  newdir = __file_name_split_at (newfd, new, (char **) &newname);
   if (newdir == MACH_PORT_NULL)
     {
-       __mach_port_deallocate (__mach_task_self (), olddir);
+      __mach_port_deallocate (__mach_task_self (), olddir);
       return -1;
     }
+  if (!*newname)
+    {
+      /* Trailing slash.  */
+      __mach_port_deallocate (__mach_task_self (), olddir);
+      __mach_port_deallocate (__mach_task_self (), newdir);
+      return __hurd_fail (ENOTDIR);
+    }
 
   err = __dir_rename (olddir, oldname, newdir, newname, excl);
   __mach_port_deallocate (__mach_task_self (), olddir);
