From: Sheng Yong Date: Fri, 13 Sep 2024 14:35:42 +0000 (+0800) Subject: erofs-utils: lib: fix sorting shared xattrs X-Git-Tag: v1.8.2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c9d13cee3f5b255a9d2030e62c6c910c956f6f75;p=platform%2Fupstream%2Ferofs-utils.git erofs-utils: lib: fix sorting shared xattrs 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 Reviewed-by: Gao Xiang Link: https://lore.kernel.org/r/20240913143542.3265071-1-shengyong@oppo.com Signed-off-by: Gao Xiang --- diff --git a/lib/xattr.c b/lib/xattr.c index 63c7fce..7fbd24b 100644 --- a/lib/xattr.c +++ b/lib/xattr.c @@ -798,10 +798,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;