1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

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
This commit is contained in:
Samuel Thibault
2025-05-12 01:52:51 +02:00
parent ae31254432
commit 2ae4ec56c2

View 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);