From: Samuel Thibault Date: Sun, 11 May 2025 23:52:51 +0000 (+0200) Subject: hurd: Make rename refuse trailing slashes [BZ #32570] X-Git-Tag: glibc-2.42~265 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ae4ec56c2b18c46ef8220bcddac4303a4b6ef1c;p=thirdparty%2Fglibc.git 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);