Skip to content

Commit

Permalink
Limit sysfs name to KOBJ_NAME_LEN
Browse files Browse the repository at this point in the history
See commit dfc166d for details.
  • Loading branch information
behlendorf committed Aug 9, 2010
1 parent 5ce3b77 commit dd11e3f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion module/zcommon/zfs_namecheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,22 @@ dataset_namecheck(const char *path, namecheck_err_t *why, char *what)
* which is the same as MAXNAMELEN used in the kernel.
* If ZFS_MAXNAMELEN value is changed, make sure to cleanup all
* places using MAXNAMELEN.
*
* When HAVE_KOBJ_NAME_LEN is defined the maximum safe kobject name
* length is 20 bytes. This 20 bytes is broken down as follows to
* provide a maximum safe <pool>/<dataset>[@snapshot] length of only
* 18 bytes. To ensure bytes are left for <dataset>[@snapshot] the
* <pool> portition is futher limited to 9 bytes. For 2.6.27 and
* newer kernels this limit is set to MAXNAMELEN.
*
* <pool>/<dataset> + <partition> + <newline>
* (18) + (1) + (1)
*/

#ifdef HAVE_KOBJ_NAME_LEN
if (strlen(path) > 18) {
#else
if (strlen(path) >= MAXNAMELEN) {
#endif /* HAVE_KOBJ_NAME_LEN */
if (why)
*why = NAME_ERR_TOOLONG;
return (-1);
Expand Down Expand Up @@ -303,8 +316,22 @@ pool_namecheck(const char *pool, namecheck_err_t *why, char *what)
* which is the same as MAXNAMELEN used in the kernel.
* If ZPOOL_MAXNAMELEN value is changed, make sure to cleanup all
* places using MAXNAMELEN.
*
* When HAVE_KOBJ_NAME_LEN is defined the maximum safe kobject name
* length is 20 bytes. This 20 bytes is broken down as follows to
* provide a maximum safe <pool>/<dataset>[@snapshot] length of only
* 18 bytes. To ensure bytes are left for <dataset>[@snapshot] the
* <pool> portition is futher limited to 8 bytes. For 2.6.27 and
* newer kernels this limit is set to MAXNAMELEN.
*
* <pool>/<dataset> + <partition> + <newline>
* (18) + (1) + (1)
*/
#ifdef HAVE_KOBJ_NAME_LEN
if (strlen(pool) > 8) {
#else
if (strlen(pool) >= MAXNAMELEN) {
#endif /* HAVE_KOBJ_NAME_LEN */
if (why)
*why = NAME_ERR_TOOLONG;
return (-1);
Expand Down

0 comments on commit dd11e3f

Please sign in to comment.