From: Keith Mannthey Date: Tue, 18 Jun 2013 16:36:31 +0000 (-0700) Subject: LU-3403 llite: error of listxattr when buffer is small X-Git-Tag: 2.4.52~31 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F63%2F6463%2F8;p=fs%2Flustre-release.git LU-3403 llite: error of listxattr when buffer is small According to the standard, listxattr(2) should return -1 and errno should be set to ERANGE if the size of the list buffer is too small to hold the result. However ll_listxattr() will return a value bigger than the size of buffer in some cases. Let's assume listxattr(2) returns SIZE when it is called with a large enough list buffer. If it's called again with a list buffer whose size is smaller than SIZE but bigger than (SIZE - 12), then listxattr(2) will return SIZE too. This patch fixes the problem. Original patch by Li Xi Signed-off-by: Keith Mannthey Change-Id: Ifb29ae900a5ee57dfde8781f7a008b6129c7bf91 Reviewed-on: http://review.whamcloud.com/6463 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Li Xi Reviewed-by: Dmitry Eremin Reviewed-by: Oleg Drokin --- diff --git a/lustre/llite/xattr.c b/lustre/llite/xattr.c index a08c58a..0f2e189 100644 --- a/lustre/llite/xattr.c +++ b/lustre/llite/xattr.c @@ -564,7 +564,12 @@ ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size) const size_t name_len = sizeof("lov") - 1; const size_t total_len = prefix_len + name_len + 1; - if (buffer && (rc + total_len) <= size) { + if (((rc + total_len) > size) && (buffer != NULL)) { + ptlrpc_req_finished(request); + return -ERANGE; + } + + if (buffer != NULL) { buffer += rc; memcpy(buffer, XATTR_LUSTRE_PREFIX, prefix_len); memcpy(buffer + prefix_len, "lov", name_len);