This only affects platforms where iopoll uses poll instead of select.

* src/iopoll.c (iopoll_internal): Don't ignore POLLERR, POLLHUP, and
POLLNVAL events when BROKEN_OUTPUT is false.
* tests/tee/tee.sh: Add a test case.
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-QSECF99X.
---
 NEWS             | 5 +++++
 src/iopoll.c     | 5 +++--
 tests/tee/tee.sh | 9 +++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 1889e6bbb..f2e6df3ed 100644
--- a/NEWS
+++ b/NEWS
@@ -361,6 +361,11 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   of a followed file.
   [bug introduced with inotify support added in coreutils-7.5]
 
+  'tee' no longer infinite loops when the reader of a full non-blocking output
+  pipe exits.  This issue only affects platforms where poll is used instead of
+  select: AIX, Solaris, Linux, Android, and macOS 11 or later.
+  [bug introduced in coreutils-9.2]
+
   'timeout --signal=ALRM -k' again honors the -k option.
   Similarly 'timeout --signal=CHLD' no longer reports "No child processes",
   or hangs as it has done since coreutils-8.27, once the command exits.
diff --git a/src/iopoll.c b/src/iopoll.c
index 0bd2d6bf6..139b29cf2 100644
--- a/src/iopoll.c
+++ b/src/iopoll.c
@@ -55,7 +55,8 @@
    to wait for an event, otherwise return the status immediately.
    Return 0 if not BLOCKing and there is no event on the requested descriptors.
    Return 0 if FDIN can be read() without blocking, or IOPOLL_BROKEN_OUTPUT if
-   FDOUT becomes a broken pipe. If !BROKEN_OUTPUT return 0 if FDOUT writable.
+   FDOUT becomes a broken pipe. If !BROKEN_OUTPUT return 0 if FDOUT writable,
+   or has an error that would cause a subsequent write to fail without 
blocking.
    Otherwise return IOPOLL_ERROR if there is a poll() or select() error.  */
 
 static int
@@ -74,7 +75,7 @@ iopoll_internal (int fdin, int fdout, bool block, bool 
broken_output)
   if (! broken_output)
     {
       pfds[0].events = pfds[1].events = POLLOUT;
-      check_out_events = POLLOUT;
+      check_out_events |= POLLOUT;
     }
 
   while (0 <= ret || errno == EINTR)
diff --git a/tests/tee/tee.sh b/tests/tee/tee.sh
index abf29246e..d2f0ed4da 100755
--- a/tests/tee/tee.sh
+++ b/tests/tee/tee.sh
@@ -120,6 +120,15 @@ read_fifo
 yes >fifo
 pipe_status=$?
 
+# Make sure that tee doesn't enter an infinite loop when a full
+# nonblocking pipe exits.
+yes |
+{
+  dd count=0 oflag=nonblock status=none
+  returns_ $pipe_status timeout 10 tee || touch tee.fail
+} | sleep .5
+test -f tee.fail && fail=1
+
 # Default operation is to continue on output errors but exit silently on 
SIGPIPE
 read_fifo
 yes | returns_ $pipe_status timeout 10 tee ./e/noent 2>err >fifo || fail=1
-- 
2.56.1


Reply via email to