diff options
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/mach/hurd/renameat2.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/sysdeps/mach/hurd/renameat2.c b/sysdeps/mach/hurd/renameat2.c index 59a4e31..5b09fed 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); |