This patch fixes a bug in the ext2 and ext3 listxattr operation: Even if an attribute is hidden from the user, the terminating NULL character was included in the listxattr result. After the patch this doesn't happen anymore. Index: linux-2.5.60/fs/ext2/acl.c --- linux-2.5.60~ext2_ext3_listxattr-bug/fs/ext2/acl.c 2003-02-11 12:30:30.000000000 +0100 +++ linux-2.5.60/fs/ext2/acl.c 2003-02-11 12:40:11.000000000 +0100 @@ -421,26 +421,26 @@ ext2_xattr_list_acl_access(char *list, struct inode *inode, const char *name, int name_len) { - const size_t len = sizeof(XATTR_NAME_ACL_ACCESS)-1; + const size_t size = sizeof(XATTR_NAME_ACL_ACCESS); if (!test_opt(inode->i_sb, POSIX_ACL)) return 0; if (list) - memcpy(list, XATTR_NAME_ACL_ACCESS, len); - return len; + memcpy(list, XATTR_NAME_ACL_ACCESS, size); + return size; } static size_t ext2_xattr_list_acl_default(char *list, struct inode *inode, const char *name, int name_len) { - const size_t len = sizeof(XATTR_NAME_ACL_DEFAULT)-1; + const size_t size = sizeof(XATTR_NAME_ACL_DEFAULT); if (!test_opt(inode->i_sb, POSIX_ACL)) return 0; if (list) - memcpy(list, XATTR_NAME_ACL_DEFAULT, len); - return len; + memcpy(list, XATTR_NAME_ACL_DEFAULT, size); + return size; } static int Index: linux-2.5.60/fs/ext2/xattr.c --- linux-2.5.60~ext2_ext3_listxattr-bug/fs/ext2/xattr.c 2003-02-11 12:30:30.000000000 +0100 +++ linux-2.5.60/fs/ext2/xattr.c 2003-02-11 12:40:11.000000000 +0100 @@ -409,10 +409,9 @@ goto bad_block; handler = ext2_xattr_handler(entry->e_name_index); - if (handler) { + if (handler) size += handler->list(NULL, inode, entry->e_name, - entry->e_name_len) + 1; - } + entry->e_name_len); } if (ext2_xattr_cache_insert(bh)) @@ -433,11 +432,9 @@ struct ext2_xattr_handler *handler; handler = ext2_xattr_handler(entry->e_name_index); - if (handler) { + if (handler) buf += handler->list(buf, inode, entry->e_name, entry->e_name_len); - *buf++ = '\0'; - } } error = size; Index: linux-2.5.60/fs/ext2/xattr_user.c --- linux-2.5.60~ext2_ext3_listxattr-bug/fs/ext2/xattr_user.c 2003-02-11 12:30:30.000000000 +0100 +++ linux-2.5.60/fs/ext2/xattr_user.c 2003-02-11 12:40:11.000000000 +0100 @@ -29,8 +29,9 @@ if (list) { memcpy(list, XATTR_USER_PREFIX, prefix_len); memcpy(list+prefix_len, name, name_len); + list[prefix_len + name_len] = '\0'; } - return prefix_len + name_len; + return prefix_len + name_len + 1; } static int Index: linux-2.5.60/fs/ext3/acl.c --- linux-2.5.60~ext2_ext3_listxattr-bug/fs/ext3/acl.c 2003-02-11 12:37:36.000000000 +0100 +++ linux-2.5.60/fs/ext3/acl.c 2003-02-11 12:40:11.000000000 +0100 @@ -434,26 +434,26 @@ ext3_xattr_list_acl_access(char *list, struct inode *inode, const char *name, int name_len) { - const size_t len = sizeof(XATTR_NAME_ACL_ACCESS)-1; + const size_t size = sizeof(XATTR_NAME_ACL_ACCESS); if (!test_opt(inode->i_sb, POSIX_ACL)) return 0; if (list) - memcpy(list, XATTR_NAME_ACL_ACCESS, len); - return len; + memcpy(list, XATTR_NAME_ACL_ACCESS, size); + return size; } static size_t ext3_xattr_list_acl_default(char *list, struct inode *inode, const char *name, int name_len) { - const size_t len = sizeof(XATTR_NAME_ACL_DEFAULT)-1; + const size_t size = sizeof(XATTR_NAME_ACL_DEFAULT); if (!test_opt(inode->i_sb, POSIX_ACL)) return 0; if (list) - memcpy(list, XATTR_NAME_ACL_DEFAULT, len); - return len; + memcpy(list, XATTR_NAME_ACL_DEFAULT, size); + return size; } static int Index: linux-2.5.60/fs/ext3/xattr.c --- linux-2.5.60~ext2_ext3_listxattr-bug/fs/ext3/xattr.c 2003-02-11 12:33:45.000000000 +0100 +++ linux-2.5.60/fs/ext3/xattr.c 2003-02-11 12:40:11.000000000 +0100 @@ -402,10 +402,9 @@ goto bad_block; handler = ext3_xattr_handler(entry->e_name_index); - if (handler) { + if (handler) size += handler->list(NULL, inode, entry->e_name, - entry->e_name_len) + 1; - } + entry->e_name_len); } if (ext3_xattr_cache_insert(bh)) @@ -426,11 +425,9 @@ struct ext3_xattr_handler *handler; handler = ext3_xattr_handler(entry->e_name_index); - if (handler) { + if (handler) buf += handler->list(buf, inode, entry->e_name, entry->e_name_len); - *buf++ = '\0'; - } } error = size; Index: linux-2.5.60/fs/ext3/xattr_user.c --- linux-2.5.60~ext2_ext3_listxattr-bug/fs/ext3/xattr_user.c 2003-02-11 12:38:02.000000000 +0100 +++ linux-2.5.60/fs/ext3/xattr_user.c 2003-02-11 12:40:11.000000000 +0100 @@ -31,8 +31,9 @@ if (list) { memcpy(list, XATTR_USER_PREFIX, prefix_len); memcpy(list+prefix_len, name, name_len); + list[prefix_len + name_len] = '\0'; } - return prefix_len + name_len; + return prefix_len + name_len + 1; } static int