* dir.cc (mkdir): Check for trailing /. or /.. component.
(rmdir): Ditto. * path.cc (has_dot_last_component): New function. * path.h (has_dot_last_component): Add declaration.
This commit is contained in:
parent
9a7b0aad2a
commit
f6c9ff6646
|
@ -255,6 +255,16 @@ mkdir (const char *dir, mode_t mode)
|
|||
int res = -1;
|
||||
fhandler_base *fh = NULL;
|
||||
|
||||
myfault efault;
|
||||
if (efault.faulted (EFAULT))
|
||||
return -1;
|
||||
|
||||
if (has_dot_last_component (dir))
|
||||
{
|
||||
set_errno (ENOENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(fh = build_fh_name (dir, NULL, PC_SYM_NOFOLLOW | PC_WRITABLE)))
|
||||
goto done; /* errno already set */;
|
||||
|
||||
|
@ -279,6 +289,16 @@ rmdir (const char *dir)
|
|||
int res = -1;
|
||||
fhandler_base *fh = NULL;
|
||||
|
||||
myfault efault;
|
||||
if (efault.faulted (EFAULT))
|
||||
return -1;
|
||||
|
||||
if (has_dot_last_component (dir))
|
||||
{
|
||||
set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(fh = build_fh_name (dir, NULL, PC_SYM_NOFOLLOW | PC_WRITABLE)))
|
||||
goto done; /* errno already set */;
|
||||
|
||||
|
|
|
@ -205,6 +205,24 @@ pathmatch (const char *path1, const char *path2)
|
|||
: strcasematch (path1, path2);
|
||||
}
|
||||
|
||||
/* TODO: This function is used in mkdir and rmdir to generate correct
|
||||
error messages in case of paths ending in /. or /.. components.
|
||||
This test should eventually end up in path_conv::check in one way
|
||||
or another. Right now, normalize_posix_path will just normalize
|
||||
those components away, which changes the semantics. */
|
||||
bool
|
||||
has_dot_last_component (const char *dir)
|
||||
{
|
||||
/* SUSv3: . and .. are not allowed as last components in various system
|
||||
calls. Don't test for backslash path separator since that's a Win32
|
||||
path following Win32 rules. */
|
||||
const char *last_comp = strrchr (dir, '/');
|
||||
return last_comp
|
||||
&& last_comp[1] == '.'
|
||||
&& (last_comp[2] == '\0'
|
||||
|| (last_comp[2] == '.' && last_comp[3] == '\0'));
|
||||
}
|
||||
|
||||
#define isslash(c) ((c) == '/')
|
||||
|
||||
/* Normalize a POSIX path.
|
||||
|
|
|
@ -289,6 +289,7 @@ has_exec_chars (const char *buf, int len)
|
|||
|
||||
int pathmatch (const char *path1, const char *path2) __attribute__ ((regparm (2)));
|
||||
int pathnmatch (const char *path1, const char *path2, int len) __attribute__ ((regparm (2)));
|
||||
bool has_dot_last_component (const char *dir) __attribute__ ((regparm (1)));
|
||||
|
||||
bool fnunmunge (char *, const char *) __attribute__ ((regparm (2)));
|
||||
|
||||
|
|
Loading…
Reference in New Issue