Commit d29f781c authored by Allison Henderson's avatar Allison Henderson Committed by Darrick J. Wong

xfs: Remove all strlen in all xfs_attr_* functions for attr names.

This helps to pre-simplify the extra handling of the null terminator in
delayed operations which use memcpy rather than strlen.  Later
when we introduce parent pointers, attribute names will become binary,
so strlen will not work at all.  Removing uses of strlen now will
help reduce complexities later
Signed-off-by: default avatarAllison Collins <allison.henderson@oracle.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent 780d2905
...@@ -62,6 +62,7 @@ xfs_attr_args_init( ...@@ -62,6 +62,7 @@ xfs_attr_args_init(
struct xfs_da_args *args, struct xfs_da_args *args,
struct xfs_inode *dp, struct xfs_inode *dp,
const unsigned char *name, const unsigned char *name,
size_t namelen,
int flags) int flags)
{ {
...@@ -74,7 +75,7 @@ xfs_attr_args_init( ...@@ -74,7 +75,7 @@ xfs_attr_args_init(
args->dp = dp; args->dp = dp;
args->flags = flags; args->flags = flags;
args->name = name; args->name = name;
args->namelen = strlen((const char *)name); args->namelen = namelen;
if (args->namelen >= MAXNAMELEN) if (args->namelen >= MAXNAMELEN)
return -EFAULT; /* match IRIX behaviour */ return -EFAULT; /* match IRIX behaviour */
...@@ -139,6 +140,7 @@ int ...@@ -139,6 +140,7 @@ int
xfs_attr_get( xfs_attr_get(
struct xfs_inode *ip, struct xfs_inode *ip,
const unsigned char *name, const unsigned char *name,
size_t namelen,
unsigned char **value, unsigned char **value,
int *valuelenp, int *valuelenp,
int flags) int flags)
...@@ -154,7 +156,7 @@ xfs_attr_get( ...@@ -154,7 +156,7 @@ xfs_attr_get(
if (XFS_FORCED_SHUTDOWN(ip->i_mount)) if (XFS_FORCED_SHUTDOWN(ip->i_mount))
return -EIO; return -EIO;
error = xfs_attr_args_init(&args, ip, name, flags); error = xfs_attr_args_init(&args, ip, name, namelen, flags);
if (error) if (error)
return error; return error;
...@@ -338,6 +340,7 @@ int ...@@ -338,6 +340,7 @@ int
xfs_attr_set( xfs_attr_set(
struct xfs_inode *dp, struct xfs_inode *dp,
const unsigned char *name, const unsigned char *name,
size_t namelen,
unsigned char *value, unsigned char *value,
int valuelen, int valuelen,
int flags) int flags)
...@@ -353,7 +356,7 @@ xfs_attr_set( ...@@ -353,7 +356,7 @@ xfs_attr_set(
if (XFS_FORCED_SHUTDOWN(dp->i_mount)) if (XFS_FORCED_SHUTDOWN(dp->i_mount))
return -EIO; return -EIO;
error = xfs_attr_args_init(&args, dp, name, flags); error = xfs_attr_args_init(&args, dp, name, namelen, flags);
if (error) if (error)
return error; return error;
...@@ -442,6 +445,7 @@ int ...@@ -442,6 +445,7 @@ int
xfs_attr_remove( xfs_attr_remove(
struct xfs_inode *dp, struct xfs_inode *dp,
const unsigned char *name, const unsigned char *name,
size_t namelen,
int flags) int flags)
{ {
struct xfs_mount *mp = dp->i_mount; struct xfs_mount *mp = dp->i_mount;
...@@ -453,7 +457,7 @@ xfs_attr_remove( ...@@ -453,7 +457,7 @@ xfs_attr_remove(
if (XFS_FORCED_SHUTDOWN(dp->i_mount)) if (XFS_FORCED_SHUTDOWN(dp->i_mount))
return -EIO; return -EIO;
error = xfs_attr_args_init(&args, dp, name, flags); error = xfs_attr_args_init(&args, dp, name, namelen, flags);
if (error) if (error)
return error; return error;
......
...@@ -148,11 +148,13 @@ int xfs_attr_list_int(struct xfs_attr_list_context *); ...@@ -148,11 +148,13 @@ int xfs_attr_list_int(struct xfs_attr_list_context *);
int xfs_inode_hasattr(struct xfs_inode *ip); int xfs_inode_hasattr(struct xfs_inode *ip);
int xfs_attr_get_ilocked(struct xfs_inode *ip, struct xfs_da_args *args); int xfs_attr_get_ilocked(struct xfs_inode *ip, struct xfs_da_args *args);
int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name, int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name,
unsigned char **value, int *valuelenp, int flags); size_t namelen, unsigned char **value, int *valuelenp,
int flags);
int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name, int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
unsigned char *value, int valuelen, int flags); size_t namelen, unsigned char *value, int valuelen, int flags);
int xfs_attr_set_args(struct xfs_da_args *args); int xfs_attr_set_args(struct xfs_da_args *args);
int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags); int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name,
size_t namelen, int flags);
int xfs_attr_remove_args(struct xfs_da_args *args); int xfs_attr_remove_args(struct xfs_da_args *args);
int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize, int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
int flags, struct attrlist_cursor_kern *cursor); int flags, struct attrlist_cursor_kern *cursor);
......
...@@ -145,7 +145,8 @@ xfs_get_acl(struct inode *inode, int type) ...@@ -145,7 +145,8 @@ xfs_get_acl(struct inode *inode, int type)
* go out to the disk. * go out to the disk.
*/ */
len = XFS_ACL_MAX_SIZE(ip->i_mount); len = XFS_ACL_MAX_SIZE(ip->i_mount);
error = xfs_attr_get(ip, ea_name, (unsigned char **)&xfs_acl, &len, error = xfs_attr_get(ip, ea_name, strlen(ea_name),
(unsigned char **)&xfs_acl, &len,
ATTR_ALLOC | ATTR_ROOT); ATTR_ALLOC | ATTR_ROOT);
if (error) { if (error) {
/* /*
...@@ -196,15 +197,17 @@ __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) ...@@ -196,15 +197,17 @@ __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
len -= sizeof(struct xfs_acl_entry) * len -= sizeof(struct xfs_acl_entry) *
(XFS_ACL_MAX_ENTRIES(ip->i_mount) - acl->a_count); (XFS_ACL_MAX_ENTRIES(ip->i_mount) - acl->a_count);
error = xfs_attr_set(ip, ea_name, (unsigned char *)xfs_acl, error = xfs_attr_set(ip, ea_name, strlen(ea_name),
len, ATTR_ROOT); (unsigned char *)xfs_acl, len, ATTR_ROOT);
kmem_free(xfs_acl); kmem_free(xfs_acl);
} else { } else {
/* /*
* A NULL ACL argument means we want to remove the ACL. * A NULL ACL argument means we want to remove the ACL.
*/ */
error = xfs_attr_remove(ip, ea_name, ATTR_ROOT); error = xfs_attr_remove(ip, ea_name,
strlen(ea_name),
ATTR_ROOT);
/* /*
* If the attribute didn't exist to start with that's fine. * If the attribute didn't exist to start with that's fine.
......
...@@ -357,6 +357,7 @@ xfs_attrmulti_attr_get( ...@@ -357,6 +357,7 @@ xfs_attrmulti_attr_get(
{ {
unsigned char *kbuf; unsigned char *kbuf;
int error = -EFAULT; int error = -EFAULT;
size_t namelen;
if (*len > XFS_XATTR_SIZE_MAX) if (*len > XFS_XATTR_SIZE_MAX)
return -EINVAL; return -EINVAL;
...@@ -364,7 +365,9 @@ xfs_attrmulti_attr_get( ...@@ -364,7 +365,9 @@ xfs_attrmulti_attr_get(
if (!kbuf) if (!kbuf)
return -ENOMEM; return -ENOMEM;
error = xfs_attr_get(XFS_I(inode), name, &kbuf, (int *)len, flags); namelen = strlen(name);
error = xfs_attr_get(XFS_I(inode), name, namelen, &kbuf, (int *)len,
flags);
if (error) if (error)
goto out_kfree; goto out_kfree;
...@@ -386,6 +389,7 @@ xfs_attrmulti_attr_set( ...@@ -386,6 +389,7 @@ xfs_attrmulti_attr_set(
{ {
unsigned char *kbuf; unsigned char *kbuf;
int error; int error;
size_t namelen;
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
return -EPERM; return -EPERM;
...@@ -396,7 +400,8 @@ xfs_attrmulti_attr_set( ...@@ -396,7 +400,8 @@ xfs_attrmulti_attr_set(
if (IS_ERR(kbuf)) if (IS_ERR(kbuf))
return PTR_ERR(kbuf); return PTR_ERR(kbuf);
error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags); namelen = strlen(name);
error = xfs_attr_set(XFS_I(inode), name, namelen, kbuf, len, flags);
if (!error) if (!error)
xfs_forget_acl(inode, name, flags); xfs_forget_acl(inode, name, flags);
kfree(kbuf); kfree(kbuf);
...@@ -410,10 +415,12 @@ xfs_attrmulti_attr_remove( ...@@ -410,10 +415,12 @@ xfs_attrmulti_attr_remove(
uint32_t flags) uint32_t flags)
{ {
int error; int error;
size_t namelen;
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
return -EPERM; return -EPERM;
error = xfs_attr_remove(XFS_I(inode), name, flags); namelen = strlen(name);
error = xfs_attr_remove(XFS_I(inode), name, namelen, flags);
if (!error) if (!error)
xfs_forget_acl(inode, name, flags); xfs_forget_acl(inode, name, flags);
return error; return error;
......
...@@ -50,8 +50,10 @@ xfs_initxattrs( ...@@ -50,8 +50,10 @@ xfs_initxattrs(
int error = 0; int error = 0;
for (xattr = xattr_array; xattr->name != NULL; xattr++) { for (xattr = xattr_array; xattr->name != NULL; xattr++) {
error = xfs_attr_set(ip, xattr->name, xattr->value, error = xfs_attr_set(ip, xattr->name,
xattr->value_len, ATTR_SECURE); strlen(xattr->name),
xattr->value, xattr->value_len,
ATTR_SECURE);
if (error < 0) if (error < 0)
break; break;
} }
......
...@@ -24,6 +24,7 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused, ...@@ -24,6 +24,7 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
int xflags = handler->flags; int xflags = handler->flags;
struct xfs_inode *ip = XFS_I(inode); struct xfs_inode *ip = XFS_I(inode);
int error, asize = size; int error, asize = size;
size_t namelen = strlen(name);
/* Convert Linux syscall to XFS internal ATTR flags */ /* Convert Linux syscall to XFS internal ATTR flags */
if (!size) { if (!size) {
...@@ -31,7 +32,8 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused, ...@@ -31,7 +32,8 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
value = NULL; value = NULL;
} }
error = xfs_attr_get(ip, name, (unsigned char **)&value, &asize, xflags); error = xfs_attr_get(ip, name, namelen, (unsigned char **)&value,
&asize, xflags);
if (error) if (error)
return error; return error;
return asize; return asize;
...@@ -67,6 +69,7 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused, ...@@ -67,6 +69,7 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,
int xflags = handler->flags; int xflags = handler->flags;
struct xfs_inode *ip = XFS_I(inode); struct xfs_inode *ip = XFS_I(inode);
int error; int error;
size_t namelen = strlen(name);
/* Convert Linux syscall to XFS internal ATTR flags */ /* Convert Linux syscall to XFS internal ATTR flags */
if (flags & XATTR_CREATE) if (flags & XATTR_CREATE)
...@@ -75,10 +78,10 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused, ...@@ -75,10 +78,10 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,
xflags |= ATTR_REPLACE; xflags |= ATTR_REPLACE;
if (value) if (value)
error = xfs_attr_set(ip, (unsigned char *)name, error = xfs_attr_set(ip, name, namelen, (void *)value, size,
(void *)value, size, xflags); xflags);
else else
error = xfs_attr_remove(ip, (unsigned char *)name, xflags); error = xfs_attr_remove(ip, name, namelen, xflags);
if (!error) if (!error)
xfs_forget_acl(inode, name, xflags); xfs_forget_acl(inode, name, xflags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment