* posix_ipc.cc (check_path): Fix typo in comment. Align naming

convention rules to Linux.  Add comment.
This commit is contained in:
Corinna Vinschen 2009-06-12 09:50:05 +00:00
parent 297abffd67
commit b32c31d117
2 changed files with 17 additions and 4 deletions

View File

@ -1,3 +1,8 @@
2009-06-12 Corinna Vinschen <corinna@vinschen.de>
* posix_ipc.cc (check_path): Fix typo in comment. Align naming
convention rules to Linux. Add comment.
2009-06-09 Corinna Vinschen <corinna@vinschen.de> 2009-06-09 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (GetSystemTimes): Remove. * autoload.cc (GetSystemTimes): Remove.

View File

@ -47,7 +47,7 @@ enum ipc_type_t
static bool static bool
check_path (char *res_name, ipc_type_t type, const char *name, size_t len) check_path (char *res_name, ipc_type_t type, const char *name, size_t len)
{ {
/* Note that we require the existance of the apprpriate /dev subdirectories /* Note that we require the existance of the appropriate /dev subdirectories
for POSIX IPC object support, similar to Linux (which supports the for POSIX IPC object support, similar to Linux (which supports the
directories, but doesn't require to mount them). We don't create directories, but doesn't require to mount them). We don't create
these directory here, that's the task of the installer. But we check these directory here, that's the task of the installer. But we check
@ -65,13 +65,21 @@ check_path (char *res_name, ipc_type_t type, const char *name, size_t len)
set_errno (EINVAL); set_errno (EINVAL);
return false; return false;
} }
/* Name must start with a single slash. */ /* Name must not be empty, or just be a single slash, or start with more
if (!name || name[0] != '/' || name[1] == '/' || !name[1]) than one slash. Same for backslash.
Apart from handling backslash like slash, the naming rules are identical
to Linux, including the names and requirements for subdirectories, if
the name contains further slashes. */
if (!name || (strchr ("/\\", name[0])
&& (!name[1] || strchr ("/\\", name[1]))))
{ {
debug_printf ("Invalid %s name '%s'", ipc_names[type].description, name); debug_printf ("Invalid %s name '%s'", ipc_names[type].description, name);
set_errno (EINVAL); set_errno (EINVAL);
return false; return false;
} }
/* Skip leading (back-)slash. */
if (strchr ("/\\", name[0]))
++name;
if (len > PATH_MAX - ipc_names[type].prefix_len) if (len > PATH_MAX - ipc_names[type].prefix_len)
{ {
debug_printf ("%s name '%s' too long", ipc_names[type].description, name); debug_printf ("%s name '%s' too long", ipc_names[type].description, name);
@ -80,7 +88,7 @@ check_path (char *res_name, ipc_type_t type, const char *name, size_t len)
} }
__small_sprintf (res_name, "%s/%s%s", ipc_names[type].prefix, __small_sprintf (res_name, "%s/%s%s", ipc_names[type].prefix,
type == semaphore ? "sem." : "", type == semaphore ? "sem." : "",
name + 1); name);
return true; return true;
} }