fs/hfsplus: use kasprintf instead of kmalloc/strcpy.
RFC 1/1 fs/hfsplus: use kasprintf instead of kmalloc/strcpy.
This patch removes prefixlen from all getxattr/setxattr callsites and maximum attribute preallocation.
It's an RFC because it could bring a memory leak somewhere if attribute is stored on the old preallocation basis and I don't know the code enough to evaluate the risk.
Suggested-by Andrew Morton <[email protected]>
Cc Andrew Morton <[email protected]>
Signed-off-by Fabian Frederick <[email protected]>
--- fs/hfsplus/xattr.c | 21 +++++++-------------- fs/hfsplus/xattr.h | 4 ++-- fs/hfsplus/xattr_security.c | 6 ++---- fs/hfsplus/xattr_trusted.c | 5 ++--- fs/hfsplus/xattr_user.c | 4 ++-- 5 files changed, 15 insertions(+), 25 deletions(-)
fs/hfsplus/xattr.c +7 -14
@@ -426,7 +426,7 @@ static int copy_name(char *buffer, const char *xattr_name, int name_len)int hfsplus_setxattr (struct dentry *dentry,const char *name,const void *value,size_t size,int flags, -const char *prefix,size_t prefixlen) +const char *prefix) {char *xattr_name;int res;
@@ -434,12 +434,10 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name,if (!strcmp (name,"" ))return -EINVAL ; - xattr_name =kmalloc (NLS_MAX_CHARSET_SIZE *HFSPLUS_ATTR_MAX_STRLEN +1 , -GFP_KERNEL ); + xattr_name =kasprintf (GFP_KERNEL ,"%s%s" , prefix, name);if (!xattr_name)return -ENOMEM ; -strcpy (xattr_name, prefix); -strcpy (xattr_name + prefixlen, name); + res =__hfsplus_setxattr (dentry->d_inode, xattr_name, value, size, flags);kfree (xattr_name);
@@ -584,7 +582,7 @@ failed_getxattr_init:ssize_t hfsplus_getxattr (struct dentry *dentry,const char *name,void *value,size_t size, -const char *prefix,size_t prefixlen) +const char *prefix) {int res;char *xattr_name;
@@ -592,14 +590,10 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,if (!strcmp (name,"" ))return -EINVAL ; - xattr_name =kmalloc (NLS_MAX_CHARSET_SIZE *HFSPLUS_ATTR_MAX_STRLEN +1 , -GFP_KERNEL ); + xattr_name =kasprintf (GFP_KERNEL ,"%s%s" , prefix, name);if (!xattr_name)return -ENOMEM ; -strcpy (xattr_name, prefix); -strcpy (xattr_name + prefixlen, name); - res =__hfsplus_getxattr (dentry->d_inode, xattr_name, value, size);kfree (xattr_name);return res;
@@ -863,7 +857,7 @@ static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name,return -EOPNOTSUPP ;return hfsplus_getxattr (dentry, name, buffer, size, -XATTR_MAC_OSX_PREFIX ,XATTR_MAC_OSX_PREFIX_LEN ); +XATTR_MAC_OSX_PREFIX ); } static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name,
@@ -880,8 +874,7 @@ static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name,return -EOPNOTSUPP ;return hfsplus_setxattr (dentry, name, buffer, size, flags, -XATTR_MAC_OSX_PREFIX , -XATTR_MAC_OSX_PREFIX_LEN ); +XATTR_MAC_OSX_PREFIX ); } static size_t hfsplus_osx_listxattr(struct dentry *dentry, char *list,
fs/hfsplus/xattr.h +2 -2
@@ -23,14 +23,14 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,int hfsplus_setxattr (struct dentry *dentry,const char *name,const void *value,size_t size,int flags, -const char *prefix,size_t prefixlen); +const char *prefix);ssize_t __hfsplus_getxattr (struct inode *inode,const char *name,void *value,size_t size);ssize_t hfsplus_getxattr (struct dentry *dentry,const char *name,void *value,size_t size, -const char *prefix,size_t prefixlen); +const char *prefix);ssize_t hfsplus_listxattr (struct dentry *dentry,char *buffer,size_t size);
fs/hfsplus/xattr_security.c +2 -4
@@ -17,16 +17,14 @@ static int hfsplus_security_getxattr(struct dentry *dentry, const char *name, void *buffer, size_t size, int type) { return hfsplus_getxattr(dentry, name, buffer, size, -XATTR_SECURITY_PREFIX , -XATTR_SECURITY_PREFIX_LEN ); +XATTR_SECURITY_PREFIX ); }static int hfsplus_security_setxattr (struct dentry *dentry,const char *name,const void *buffer,size_t size,int flags,int type) {return hfsplus_setxattr (dentry, name, buffer, size, flags, -XATTR_SECURITY_PREFIX , -XATTR_SECURITY_PREFIX_LEN ); +XATTR_SECURITY_PREFIX ); } static size_t hfsplus_security_listxattr(struct dentry *dentry, char *list,
fs/hfsplus/xattr_trusted.c +2 -3
@@ -15,15 +15,14 @@ static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name, void *buffer, size_t size, int type) { return hfsplus_getxattr(dentry, name, buffer, size, -XATTR_TRUSTED_PREFIX , -XATTR_TRUSTED_PREFIX_LEN ); +XATTR_TRUSTED_PREFIX ); }static int hfsplus_trusted_setxattr (struct dentry *dentry,const char *name,const void *buffer,size_t size,int flags,int type) {return hfsplus_setxattr (dentry, name, buffer, size, flags, -XATTR_TRUSTED_PREFIX ,XATTR_TRUSTED_PREFIX_LEN ); +XATTR_TRUSTED_PREFIX ); } static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char *list,
fs/hfsplus/xattr_user.c +2 -2
@@ -16,14 +16,14 @@ static int hfsplus_user_getxattr(struct dentry *dentry, const char *name, {return hfsplus_getxattr (dentry, name, buffer, size, -XATTR_USER_PREFIX ,XATTR_USER_PREFIX_LEN ); +XATTR_USER_PREFIX ); }static int hfsplus_user_setxattr (struct dentry *dentry,const char *name,const void *buffer,size_t size,int flags,int type) {return hfsplus_setxattr (dentry, name, buffer, size, flags, -XATTR_USER_PREFIX ,XATTR_USER_PREFIX_LEN ); +XATTR_USER_PREFIX ); } static size_t hfsplus_user_listxattr(struct dentry *dentry, char *list,
Signature · 1 line
1.9.1