[Toybox] [PATCH] getfattx.c: fix overlayfs merged dir stuck

Weizhao Ouyang o451686892 at gmail.com
Tue Aug 30 08:49:41 PDT 2022


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 call to fix it.

Signed-off-by: Weizhao Ouyang <o451686892 at gmail.com>
---
 toys/pending/getfattr.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/toys/pending/getfattr.c b/toys/pending/getfattr.c
index bf2c04c8..aa2c3958 100644
--- a/toys/pending/getfattr.c
+++ b/toys/pending/getfattr.c
@@ -43,15 +43,22 @@ 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;
+  keys_len = lister(file, NULL, 0);
+  if (keys_len < 0)
+    perror_exit("listxattr failed");
+  else if (keys_len == 0)
+    return;
+
+  keys = xmalloc(keys_len);
+  keys_len = lister(file, keys, keys_len);
+  if (keys_len < 0) {
     free(keys);
+    perror_exit("listxattr failed");
+  } else if (keys_len == 0) {
+    free(keys);
+    return;
   }
 
-  if (keys_len == 0) return;
-
   // Sort the keys.
   for (key = keys, key_count = 0; key-keys < keys_len; key += strlen(key)+1)
     key_count++;
-- 
2.34.1



More information about the Toybox mailing list