This was seen on termux with ./configure --disable-xattr
where listxattr() and getxattr() returned ENOTSUP.
Then the valid security context obtained by file_has_aclinfo()
was discounted, and problematically then freed multiple times.
Reported at https://github.com/termux/termux-packages/issues/23752
* src/ls.c (file_has_aclinfo_cache): Only discount the returned
acl info when all components are defaulted due to being unsupported.
---
NEWS | 3 ++-
src/ls.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index 902bdaf0e..bc49825d8 100644
--- a/NEWS
+++ b/NEWS
@@ -15,7 +15,8 @@ GNU coreutils NEWS -*-
outline -*-
cache for the whole file. Previously it may have erroneously succeeded.
[bug introduced with the "nocache" feature in coreutils-8.11]
- 'ls -Z dir' would crash.
+ 'ls -Z dir' would crash on all systems, and 'ls -l' could crash
+ on systems with SELinux but without xattr support.
[bug introduced in coreutils-9.6]
'who -m' now outputs entries for remote logins. Previously login
diff --git a/src/ls.c b/src/ls.c
index 23309b812..244484439 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -3327,7 +3327,8 @@ file_has_aclinfo_cache (char const *file, struct fileinfo
*f,
errno = 0;
int n = file_has_aclinfo (file, ai, flags);
int err = errno;
- if (f->stat_ok && n <= 0 && !acl_errno_valid (err))
+ if (f->stat_ok && n <= 0 && !acl_errno_valid (err)
+ && (!(flags & ACL_GET_SCONTEXT) || !acl_errno_valid (ai->scontext_err)))
{
unsupported_return = n;
unsupported_scontext = ai->scontext;
--
2.48.1