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 <[email protected]> --- 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 _______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
