]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tail: avoid undefined behavior when polling outputs
authorPádraig Brady <P@draigBrady.com>
Tue, 28 Feb 2023 13:34:31 +0000 (13:34 +0000)
committerPádraig Brady <P@draigBrady.com>
Tue, 28 Feb 2023 14:04:16 +0000 (14:04 +0000)
* src/tail.c (check_output_alive): Only check the returned
events from poll() when it indicates there are events to check.

src/tail.c

index e2e7f46909c72d14a93eeb108a643db9af85ce60..78022fc4b5edce1edbd6e280707513adcada4c62 100644 (file)
@@ -367,9 +367,9 @@ check_output_alive (void)
   struct pollfd pfd;
   pfd.fd = STDOUT_FILENO;
   pfd.events = pfd.revents = 0;
-  pfd.events |= POLLRDBAND; /* Needed for illumos, macos.  */
+  pfd.events |= POLLRDBAND; /* Needed for illumos, macOS.  */
 
-  if (poll (&pfd, 1, 0) >= 0 && (pfd.revents & (POLLERR | POLLHUP)))
+  if (poll (&pfd, 1, 0) > 0 && (pfd.revents & (POLLERR | POLLHUP)))
     die_pipe ();
 #else
   struct timeval delay;