ext4_xattr: fix xattr functions not recognizing acl attribute name.
authorngkaho1234 <ngkaho1234@gmail.com>
Thu, 17 Mar 2016 04:27:53 +0000 (04:27 +0000)
committerngkaho1234 <ngkaho1234@gmail.com>
Thu, 17 Mar 2016 04:27:53 +0000 (04:27 +0000)
include/ext4_xattr.h
src/ext4.c
src/ext4_xattr.c

index 9345ea11ea406b2b0cf82312600e959f2d22aeea..65eb7688baa50858bf6dc1677304565092f346c8 100644 (file)
@@ -101,7 +101,8 @@ void ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref,
 void ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref);
 
 const char *ext4_extract_xattr_name(const char *full_name, size_t full_name_len,
-                             uint8_t *name_index, size_t *name_len);
+                             uint8_t *name_index, size_t *name_len,
+                             bool *found);
 
 const char *ext4_get_xattr_name_prefix(uint8_t name_index,
                                       size_t *ret_prefix_len);
index a24f40f478888f6322d63ff167d377bfcccd9bdf..78afe9b62a1beab323a9aab373fb1b7c669205b9 100644 (file)
@@ -2391,6 +2391,7 @@ Finish:
 int ext4_setxattr(const char *path, const char *name, size_t name_len,
                  const void *data, size_t data_size, bool replace)
 {
+       bool found;
        int r = EOK;
        ext4_file f;
        uint32_t inode;
@@ -2407,8 +2408,9 @@ int ext4_setxattr(const char *path, const char *name, size_t name_len,
                return EROFS;
 
        dissected_name = ext4_extract_xattr_name(name, name_len,
-                               &name_index, &dissected_len);
-       if (!dissected_len)
+                               &name_index, &dissected_len,
+                               &found);
+       if (!found)
                return EINVAL;
 
        EXT4_MP_LOCK(mp);
@@ -2448,6 +2450,7 @@ Finish:
 int ext4_getxattr(const char *path, const char *name, size_t name_len,
                  void *buf, size_t buf_size, size_t *data_size)
 {
+       bool found;
        int r = EOK;
        ext4_file f;
        uint32_t inode;
@@ -2461,8 +2464,9 @@ int ext4_getxattr(const char *path, const char *name, size_t name_len,
                return ENOENT;
 
        dissected_name = ext4_extract_xattr_name(name, name_len,
-                               &name_index, &dissected_len);
-       if (!dissected_len)
+                               &name_index, &dissected_len,
+                               &found);
+       if (!found)
                return EINVAL;
 
        EXT4_MP_LOCK(mp);
@@ -2583,6 +2587,7 @@ Finish:
 
 int ext4_removexattr(const char *path, const char *name, size_t name_len)
 {
+       bool found;
        int r = EOK;
        ext4_file f;
        uint32_t inode;
@@ -2599,8 +2604,9 @@ int ext4_removexattr(const char *path, const char *name, size_t name_len)
                return EROFS;
 
        dissected_name = ext4_extract_xattr_name(name, name_len,
-                                               &name_index, &dissected_len);
-       if (!dissected_len)
+                                               &name_index, &dissected_len,
+                                               &found);
+       if (!found)
                return EINVAL;
 
        EXT4_MP_LOCK(mp);
index f5b05715503d0f3953f38afc35547362d6949c3d..086245ecdb539b519e50fb2b527be0680b7e7bb3 100644 (file)
@@ -893,10 +893,15 @@ static const struct xattr_prefix prefix_tbl[] = {
 };
 
 const char *ext4_extract_xattr_name(const char *full_name, size_t full_name_len,
-                             uint8_t *name_index, size_t *name_len)
+                             uint8_t *name_index, size_t *name_len,
+                             bool *found)
 {
        int i;
        ext4_assert(name_index);
+       ext4_assert(found);
+
+       *found = false;
+
        if (!full_name_len) {
                if (name_len)
                        *name_len = 0;
@@ -908,11 +913,20 @@ const char *ext4_extract_xattr_name(const char *full_name, size_t full_name_len,
                size_t prefix_len = strlen(prefix_tbl[i].prefix);
                if (full_name_len >= prefix_len &&
                    !memcmp(full_name, prefix_tbl[i].prefix, prefix_len)) {
+                       bool require_name =
+                               prefix_tbl[i].prefix[prefix_len - 1] == '.';
                        *name_index = prefix_tbl[i].name_index;
                        if (name_len)
                                *name_len = full_name_len - prefix_len;
 
-                       return full_name + prefix_len;
+                       if (!(full_name_len - prefix_len) && require_name)
+                               return NULL;
+
+                       *found = true;
+                       if (require_name)
+                               return full_name + prefix_len;
+
+                       return NULL;
                }
        }
        if (name_len)