]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Make rename refuse trailing slashes [BZ #32570]
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 11 May 2025 23:52:51 +0000 (01:52 +0200)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 11 May 2025 23:54:34 +0000 (01:54 +0200)
As tested by Gnulib's renameatu module.

Reported by Collin Funk on
https://sourceware.org/bugzilla/show_bug.cgi?id=32570

sysdeps/mach/hurd/renameat2.c

index 59a4e314fcc1136df6e166cca24823f9cdad13da..5b09fedf7f771178e2313466349c1de008e1bc2a 100644 (file)
@@ -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);