shithub: lwext4

Download patch

ref: b088876e58e9d57b0066f10d96ba02985457fda7
parent: 0df604ce1c4268176aa9925b3deb6e05294ec145
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Thu Mar 17 00:27:53 EDT 2016

ext4_xattr: fix xattr functions not recognizing acl attribute name.

--- a/include/ext4_xattr.h
+++ b/include/ext4_xattr.h
@@ -101,7 +101,8 @@
 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);
--- a/src/ext4.c
+++ b/src/ext4.c
@@ -2391,6 +2391,7 @@
 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 @@
 		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 @@
 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 @@
 		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 @@
 
 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 @@
 		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);
--- a/src/ext4_xattr.c
+++ b/src/ext4_xattr.c
@@ -893,10 +893,15 @@
 };
 
 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 @@
 		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)