From: Gao Xiang Date: Fri, 31 May 2024 07:13:05 +0000 (+0800) Subject: erofs-utils: lib: fix incorrect xattr sharing X-Git-Tag: v1.8~64 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b2f6da8ac935f44b026b01977819582d9c5831fc;p=platform%2Fupstream%2Ferofs-utils.git erofs-utils: lib: fix incorrect xattr sharing There are off-by-one issues after refactoring, and the size of kvbuf should be calculated by EROFS_XATTR_KVSIZE instead. Fixes: 5df285cf405d ("erofs-utils: lib: refactor extended attribute name prefixes") Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20240531071305.1183728-1-hsiangkao@linux.alibaba.com --- diff --git a/lib/xattr.c b/lib/xattr.c index 427933f..0f6fbe2 100644 --- a/lib/xattr.c +++ b/lib/xattr.c @@ -166,14 +166,6 @@ static unsigned int BKDRHash(char *str, unsigned int len) return hash; } -static unsigned int xattr_item_hash(char *buf, unsigned int len[2], - unsigned int hash[2]) -{ - hash[0] = BKDRHash(buf, len[0]); /* key */ - hash[1] = BKDRHash(buf + len[0], len[1]); /* value */ - return hash[0] ^ hash[1]; -} - static unsigned int put_xattritem(struct xattr_item *item) { if (item->count > 1) @@ -188,11 +180,13 @@ static struct xattr_item *get_xattritem(char *kvbuf, unsigned int len[2]) struct ea_type_node *tnode; unsigned int hash[2], hkey; - hkey = xattr_item_hash(kvbuf, len, hash); + hash[0] = BKDRHash(kvbuf, len[0]); + hash[1] = BKDRHash(kvbuf + EROFS_XATTR_KSIZE(len), len[1]); + hkey = hash[0] ^ hash[1]; hash_for_each_possible(ea_hashtable, item, node, hkey) { if (item->len[0] == len[0] && item->len[1] == len[1] && item->hash[0] == hash[0] && item->hash[1] == hash[1] && - !memcmp(kvbuf, item->kvbuf, len[0] + len[1])) { + !memcmp(kvbuf, item->kvbuf, EROFS_XATTR_KVSIZE(len))) { free(kvbuf); ++item->count; return item;