On 17/01/2025 17:23, Pádraig Brady wrote:
On 17/01/2025 16:17, Pádraig Brady wrote:On 17/01/2025 16:00, Bruno Haible wrote:On - OpenBSD 6.0, - NetBSD 7.1 I see a test failure:
The cause is a crash that is easy to reproduce interactively: $ src/ls -Z .
Attached is a more complete patch for this. Distros can apply this at least until we do another release. cheers, Pádraig
From 14f2d2317b2f935cb2277a4140c1afa569be9629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]> Date: Fri, 17 Jan 2025 17:29:34 +0000 Subject: [PATCH] ls: fix crash with --context * src/ls.c (main): Flag that we need to stat() if we're going to get security context (call file_has_aclinfo_cache). (file_has_aclinfo_cache): Be defensive and only lookup the device for the file if the stat has been performed. (has_capability_cache): Likewise. * tests/ls/selinux-segfault.sh: Add a test case. * NEWS: Mention the bug fix. Reported by Bruno Haible. --- NEWS | 5 +++++ src/ls.c | 6 +++--- tests/ls/selinux-segfault.sh | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 9be61e4c4..c9ba5f196 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,11 @@ GNU coreutils NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** Bug fixes + + `ls -Z dir` would crash. + [bug introduced in coreutils-9.6] + * Noteworthy changes in release 9.6 (2025-01-17) [stable] diff --git a/src/ls.c b/src/ls.c index 321536021..043ddbb9c 100644 --- a/src/ls.c +++ b/src/ls.c @@ -1768,7 +1768,7 @@ main (int argc, char **argv) format_needs_stat = ((sort_type == sort_time) | (sort_type == sort_size) | (format == long_format) - | print_block_size | print_hyperlink); + | print_block_size | print_hyperlink | print_scontext); format_needs_type = ((! format_needs_stat) & (recursive | print_with_color | print_scontext | directories_first @@ -3309,7 +3309,7 @@ file_has_aclinfo_cache (char const *file, struct fileinfo *f, static int unsupported_scontext_err; static dev_t unsupported_device; - if (f->stat.st_dev == unsupported_device) + if (f->stat_ok && f->stat.st_dev == unsupported_device) { ai->buf = ai->u.__gl_acl_ch; ai->size = 0; @@ -3342,7 +3342,7 @@ has_capability_cache (char const *file, struct fileinfo *f) found that has_capability fails indicating lack of support. */ static dev_t unsupported_device; - if (f->stat.st_dev == unsupported_device) + if (f->stat_ok && f->stat.st_dev == unsupported_device) { errno = ENOTSUP; return 0; diff --git a/tests/ls/selinux-segfault.sh b/tests/ls/selinux-segfault.sh index 11623acb3..1cac2b5fc 100755 --- a/tests/ls/selinux-segfault.sh +++ b/tests/ls/selinux-segfault.sh @@ -30,4 +30,7 @@ mkdir sedir || framework_failure_ ln -sf missing sedir/broken || framework_failure_ returns_ 1 ls -L -R -Z -m sedir > out || fail=1 +# ls 9.6 would segfault with the following +ls -Z . > out || fail=1 + Exit $fail -- 2.47.1
