]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: fix crash on systems with SELinux but without xattr support
authorPádraig Brady <P@draigBrady.com>
Thu, 20 Mar 2025 18:40:01 +0000 (18:40 +0000)
committerPádraig Brady <P@draigBrady.com>
Fri, 21 Mar 2025 12:13:12 +0000 (12:13 +0000)
This was seen on termux on Android 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
src/ls.c

diff --git a/NEWS b/NEWS
index 902bdaf0e35ddb69e04a2d8d4f432a2af7263678..dfafa8ab22c10e2e2577130b8e78707fdd31cfe1 100644 (file)
--- 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 like Android with SELinux but without xattr support.
   [bug introduced in coreutils-9.6]
 
   'who -m' now outputs entries for remote logins.  Previously login
index 23309b812696089db962fe3fbc16fc2df3d39692..244484439ff8f3114f8a4561308388de88a26e04 100644 (file)
--- 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;