erofs-utils: lib: allow xattr e_name_index as 0
authorGao Xiang <hsiangkao@linux.alibaba.com>
Mon, 29 Jul 2024 07:50:26 +0000 (15:50 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 30 Jul 2024 01:57:13 +0000 (09:57 +0800)
Since it's implicitly supported since the initial EROFS kernel version.

It is particularly useful as an on-disk inode xattr placeholder for
on-disk core inode in-place updates, especially for root inodes because
"root_nid" recorded in the on-disk superblock is limited to 16 bits
for now.

Fixes: 1e429b74bff8 ("erofs-utils: lib: fix potential out-of-bound in xattr_entrylist()")
Reviewed-by: Sandeep Dhavale <dhavale@google.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240729075027.712339-1-hsiangkao@linux.alibaba.com
lib/xattr.c

index 52c0ea4cbda319ad609e234e6b470631d1aa1cf2..563c6887cefdd71ec76037bc861c977670f0bdfe 100644 (file)
@@ -1450,7 +1450,7 @@ static int xattr_entrylist(struct xattr_iter *_it,
                base_index = pf->prefix->base_index;
        }
 
-       if (base_index >= ARRAY_SIZE(xattr_types))
+       if (!base_index || base_index >= ARRAY_SIZE(xattr_types))
                return 1;
        prefix = xattr_types[base_index].prefix;
        prefix_len = xattr_types[base_index].prefix_len;