All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] erofs-utils: lib: fix sorting shared xattrs
@ 2024-09-13 14:35 Sheng Yong via Linux-erofs
  2024-09-13 15:39 ` Gao Xiang via Linux-erofs
  0 siblings, 1 reply; 2+ messages in thread
From: Sheng Yong via Linux-erofs @ 2024-09-13 14:35 UTC (permalink / raw)
  To: hsiangkao, chao; +Cc: linux-erofs, Sheng Yong

The length of xattr_item->kvbuf is calculated by EROFS_XATTR_KVSIZE,
and the key part has a trailing '\0' before the value part. When qsort
compares two xattr_items, the key-value length should be calculated by
EROFS_XATTR_KVSIZE, and use memcmp instead of strncmp to avoid key-value
string being cut by '\0'.

Fixes: 5df285cf405d ("erofs-utils: lib: refactor extended attribute name prefixes")
Signed-off-by: Sheng Yong <shengyong@oppo.com>
---
 lib/xattr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/xattr.c b/lib/xattr.c
index 651657f979cc..1dbb6e7bde49 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -794,10 +794,10 @@ static int comp_shared_xattr_item(const void *a, const void *b)
 
 	ia = *((const struct xattr_item **)a);
 	ib = *((const struct xattr_item **)b);
-	la = ia->len[0] + ia->len[1];
-	lb = ib->len[0] + ib->len[1];
+	la = EROFS_XATTR_KVSIZE(ia->len);
+	lb = EROFS_XATTR_KVSIZE(ib->len);
 
-	ret = strncmp(ia->kvbuf, ib->kvbuf, min(la, lb));
+	ret = memcmp(ia->kvbuf, ib->kvbuf, min(la, lb));
 	if (ret != 0)
 		return ret;
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-09-13 15:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-13 14:35 [PATCH] erofs-utils: lib: fix sorting shared xattrs Sheng Yong via Linux-erofs
2024-09-13 15:39 ` Gao Xiang via Linux-erofs

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.