[Toybox] [PATCH] getfattr.c: fix overlayfs merged dir stuck
Rob Landley
rob at landley.net
Wed Aug 31 03:48:17 PDT 2022
On 8/31/22 05:35, Rob Landley wrote:
> On 8/30/22 10:31, Weizhao Ouyang wrote:
>> When getfattx reading overlayfs merged dirs, listxattr will got
>> different keys_len with zero size and determined size, then it will
>> stuck in this while scope. Update the keys_len after the second
>> listxattr to fix it.
>
> Do you have a test case I can use to reproduce this? (I've never used xattrs
> together with overlayfs before.)
>
> Also, I believe Elliott has a different implementation of getfattr in android
> (for some sort of C++ library reasons, I'd have to check my notes), so he'll
> probably want the test case there too?
Would this approach work for you?
diff --git a/toys/pending/getfattr.c b/toys/pending/getfattr.c
index bf2c04c8..dbbcfde7 100644
--- a/toys/pending/getfattr.c
+++ b/toys/pending/getfattr.c
@@ -33,8 +33,8 @@ static void do_getfattr(char *file)
ssize_t (*getter)(const char *, const char *, void *, size_t) = getxattr;
ssize_t (*lister)(const char *, char *, size_t) = listxattr;
char **sorted_keys;
- ssize_t keys_len;
- char *keys, *key;
+ ssize_t keys_len = 0, len2;
+ char *keys = 0, *key;
int i, key_count;
if (FLAG(h)) {
@@ -43,14 +43,11 @@ static void do_getfattr(char *file)
}
// Collect the keys.
- while ((keys_len = lister(file, NULL, 0))) {
- if (keys_len == -1) perror_msg("listxattr failed");
- keys = xmalloc(keys_len);
- if (lister(file, keys, keys_len) == keys_len) break;
- free(keys);
+ while (keys_len != (len2 = lister(file, keys, keys_len))) {
+ if (keys_len == -1) perror_exit("listxattr");
+ keys = xrealloc(keys, keys_len = len2);
}
-
- if (keys_len == 0) return;
+ if (!keys_len) return;
// Sort the keys.
for (key = keys, key_count = 0; key-keys < keys_len; key += strlen(key)+1)
More information about the Toybox
mailing list