@@ -6296,8 +6296,8 @@ nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len)
int len = 0;
if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) {
- len = security_inode_listsecurity(inode, list, len);
- if (len > list_len)
+ len = security_inode_listsecurity(inode, list, list_len);
+ if (list_len && len > list_len)
return -ERANGE;
}
return len;
@@ -723,21 +723,23 @@ generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
if (!buffer) {
for_each_xattr_handler(handlers, handler) {
- if (handler->list(dentry))
- size += strlen(handler->name) + 1;
+ if (!handler->name ||
+ (handler->list && !handler->list(dentry)))
+ continue;
+ size += strlen(handler->name) + 1;
}
} else {
char *buf = buffer;
size_t len;
for_each_xattr_handler(handlers, handler) {
- if (!handler->list(dentry))
+ if (!handler->name ||
+ (handler->list && !handler->list(dentry)))
continue;
len = strlen(handler->name);
if (len + 1 > buffer_size)
return -ERANGE;
- memcpy(buf, handler->name, len);
- buf[len] = 0;
+ memcpy(buf, handler->name, len + 1);
buf += len + 1;
buffer_size -= len + 1;
}