Fix some POSIX-compliance bugs in link, rename, mkdir.

* syscalls.cc (link): Delete obsolete comment.  Reject directories
and missing source up front.
(rename): Use correct errno for trailing '.'.  Detect empty
strings.  Allow trailing slash to newpath iff oldpath is
directory.
* dir.cc (mkdir): Reject dangling symlink with trailing slash.
* fhandler_disk_file.cc (fhandler_disk_file::link): Reject
trailing slash.
* fhandler.cc (fhandler_base::link): Match Linux errno.
This commit is contained in:
Eric Blake
2009-09-26 15:51:53 +00:00
parent 1e6459d3e5
commit 52dba6a5c4
5 changed files with 109 additions and 42 deletions

View File

@ -1186,7 +1186,8 @@ fhandler_disk_file::ftruncate (_off64_t length, bool allow_truncate)
int
fhandler_disk_file::link (const char *newpath)
{
path_conv newpc (newpath, PC_SYM_NOFOLLOW | PC_POSIX, stat_suffixes);
size_t nlen = strlen (newpath);
path_conv newpc (newpath, PC_SYM_NOFOLLOW | PC_POSIX | PC_NULLEMPTY, stat_suffixes);
if (newpc.error)
{
set_errno (newpc.error);
@ -1200,7 +1201,13 @@ fhandler_disk_file::link (const char *newpath)
return -1;
}
char new_buf[strlen (newpath) + 5];
if (isdirsep (newpath[nlen - 1]) || has_dot_last_component (newpath, false))
{
set_errno (ENOENT);
return -1;
}
char new_buf[nlen + 5];
if (!newpc.error)
{
if (pc.is_lnk_special ())