xfs: Remove all strlen in all xfs_attr_* functions for attr names.
authorAllison Henderson <allison.henderson@oracle.com>
Tue, 7 Jan 2020 23:26:15 +0000 (15:26 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Thu, 9 Jan 2020 18:55:19 +0000 (10:55 -0800)
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: Allison Collins <allison.henderson@oracle.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
fs/xfs/libxfs/xfs_attr.c
fs/xfs/libxfs/xfs_attr.h
fs/xfs/xfs_acl.c
fs/xfs/xfs_ioctl.c
fs/xfs/xfs_iops.c
fs/xfs/xfs_xattr.c

index 2368a1b..e614972 100644 (file)
@@ -62,6 +62,7 @@ xfs_attr_args_init(
        struct xfs_da_args      *args,
        struct xfs_inode        *dp,
        const unsigned char     *name,
+       size_t                  namelen,
        int                     flags)
 {
 
@@ -74,7 +75,7 @@ xfs_attr_args_init(
        args->dp = dp;
        args->flags = flags;
        args->name = name;
-       args->namelen = strlen((const char *)name);
+       args->namelen = namelen;
        if (args->namelen >= MAXNAMELEN)
                return -EFAULT;         /* match IRIX behaviour */
 
@@ -139,6 +140,7 @@ int
 xfs_attr_get(
        struct xfs_inode        *ip,
        const unsigned char     *name,
+       size_t                  namelen,
        unsigned char           **value,
        int                     *valuelenp,
        int                     flags)
@@ -154,7 +156,7 @@ xfs_attr_get(
        if (XFS_FORCED_SHUTDOWN(ip->i_mount))
                return -EIO;
 
-       error = xfs_attr_args_init(&args, ip, name, flags);
+       error = xfs_attr_args_init(&args, ip, name, namelen, flags);
        if (error)
                return error;
 
@@ -338,6 +340,7 @@ int
 xfs_attr_set(
        struct xfs_inode        *dp,
        const unsigned char     *name,
+       size_t                  namelen,
        unsigned char           *value,
        int                     valuelen,
        int                     flags)
@@ -353,7 +356,7 @@ xfs_attr_set(
        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return -EIO;
 
-       error = xfs_attr_args_init(&args, dp, name, flags);
+       error = xfs_attr_args_init(&args, dp, name, namelen, flags);
        if (error)
                return error;
 
@@ -442,6 +445,7 @@ int
 xfs_attr_remove(
        struct xfs_inode        *dp,
        const unsigned char     *name,
+       size_t                  namelen,
        int                     flags)
 {
        struct xfs_mount        *mp = dp->i_mount;
@@ -453,7 +457,7 @@ xfs_attr_remove(
        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return -EIO;
 
-       error = xfs_attr_args_init(&args, dp, name, flags);
+       error = xfs_attr_args_init(&args, dp, name, namelen, flags);
        if (error)
                return error;
 
index 91c2cb1..4243b22 100644 (file)
@@ -148,11 +148,13 @@ int xfs_attr_list_int(struct xfs_attr_list_context *);
 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(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,
-                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_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_list(struct xfs_inode *dp, char *buffer, int bufsize,
                  int flags, struct attrlist_cursor_kern *cursor);
index 91693fc..cd743fa 100644 (file)
@@ -145,7 +145,8 @@ xfs_get_acl(struct inode *inode, int type)
         * go out to the disk.
         */
        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);
        if (error) {
                /*
@@ -196,15 +197,17 @@ __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
                len -= sizeof(struct xfs_acl_entry) *
                         (XFS_ACL_MAX_ENTRIES(ip->i_mount) - acl->a_count);
 
-               error = xfs_attr_set(ip, ea_name, (unsigned char *)xfs_acl,
-                               len, ATTR_ROOT);
+               error = xfs_attr_set(ip, ea_name, strlen(ea_name),
+                                    (unsigned char *)xfs_acl, len, ATTR_ROOT);
 
                kmem_free(xfs_acl);
        } else {
                /*
                 * 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.
index 17b4a98..d42de92 100644 (file)
@@ -357,6 +357,7 @@ xfs_attrmulti_attr_get(
 {
        unsigned char           *kbuf;
        int                     error = -EFAULT;
+       size_t                  namelen;
 
        if (*len > XFS_XATTR_SIZE_MAX)
                return -EINVAL;
@@ -364,7 +365,9 @@ xfs_attrmulti_attr_get(
        if (!kbuf)
                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)
                goto out_kfree;
 
@@ -386,6 +389,7 @@ xfs_attrmulti_attr_set(
 {
        unsigned char           *kbuf;
        int                     error;
+       size_t                  namelen;
 
        if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
                return -EPERM;
@@ -396,7 +400,8 @@ xfs_attrmulti_attr_set(
        if (IS_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)
                xfs_forget_acl(inode, name, flags);
        kfree(kbuf);
@@ -410,10 +415,12 @@ xfs_attrmulti_attr_remove(
        uint32_t                flags)
 {
        int                     error;
+       size_t                  namelen;
 
        if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
                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)
                xfs_forget_acl(inode, name, flags);
        return error;
index 8afe69c..81f2f93 100644 (file)
@@ -50,8 +50,10 @@ xfs_initxattrs(
        int                     error = 0;
 
        for (xattr = xattr_array; xattr->name != NULL; xattr++) {
-               error = xfs_attr_set(ip, xattr->name, xattr->value,
-                                     xattr->value_len, ATTR_SECURE);
+               error = xfs_attr_set(ip, xattr->name,
+                                    strlen(xattr->name),
+                                    xattr->value, xattr->value_len,
+                                    ATTR_SECURE);
                if (error < 0)
                        break;
        }
index 2288f20..b0fedb5 100644 (file)
@@ -24,6 +24,7 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
        int xflags = handler->flags;
        struct xfs_inode *ip = XFS_I(inode);
        int error, asize = size;
+       size_t namelen = strlen(name);
 
        /* Convert Linux syscall to XFS internal ATTR flags */
        if (!size) {
@@ -31,7 +32,8 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
                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)
                return error;
        return asize;
@@ -67,6 +69,7 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,
        int                     xflags = handler->flags;
        struct xfs_inode        *ip = XFS_I(inode);
        int                     error;
+       size_t                  namelen = strlen(name);
 
        /* Convert Linux syscall to XFS internal ATTR flags */
        if (flags & XATTR_CREATE)
@@ -75,10 +78,10 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,
                xflags |= ATTR_REPLACE;
 
        if (value)
-               error = xfs_attr_set(ip, (unsigned char *)name,
-                               (void *)value, size, xflags);
+               error = xfs_attr_set(ip, name, namelen, (void *)value, size,
+                               xflags);
        else
-               error = xfs_attr_remove(ip, (unsigned char *)name, xflags);
+               error = xfs_attr_remove(ip, name, namelen, xflags);
        if (!error)
                xfs_forget_acl(inode, name, xflags);