]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - fs/hfsplus/xattr_trusted.c
hfsplus: correct usage of HFSPLUS_ATTR_MAX_STRLEN for non-English attributes
[karo-tx-linux.git] / fs / hfsplus / xattr_trusted.c
index 426cee277542c4dc6638c37a485ea560aca6ef27..3c5f27e4746a918a208946691699c81cf76da8cf 100644 (file)
@@ -6,43 +6,51 @@
  * Handler for trusted extended attributes.
  */
 
+#include <linux/nls.h>
+
 #include "hfsplus_fs.h"
 #include "xattr.h"
 
 static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name,
                                        void *buffer, size_t size, int type)
 {
-       char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0};
-       size_t len = strlen(name);
+       char *xattr_name;
+       int res;
 
        if (!strcmp(name, ""))
                return -EINVAL;
 
-       if (len + XATTR_TRUSTED_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN)
-               return -EOPNOTSUPP;
-
+       xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
+               GFP_KERNEL);
+       if (!xattr_name)
+               return -ENOMEM;
        strcpy(xattr_name, XATTR_TRUSTED_PREFIX);
        strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name);
 
-       return hfsplus_getxattr(dentry, xattr_name, buffer, size);
+       res = hfsplus_getxattr(dentry, xattr_name, buffer, size);
+       kfree(xattr_name);
+       return res;
 }
 
 static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name,
                const void *buffer, size_t size, int flags, int type)
 {
-       char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0};
-       size_t len = strlen(name);
+       char *xattr_name;
+       int res;
 
        if (!strcmp(name, ""))
                return -EINVAL;
 
-       if (len + XATTR_TRUSTED_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN)
-               return -EOPNOTSUPP;
-
+       xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
+               GFP_KERNEL);
+       if (!xattr_name)
+               return -ENOMEM;
        strcpy(xattr_name, XATTR_TRUSTED_PREFIX);
        strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name);
 
-       return hfsplus_setxattr(dentry, xattr_name, buffer, size, flags);
+       res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags);
+       kfree(xattr_name);
+       return res;
 }
 
 static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char *list,