diff options
author | Pádraig Brady <P@draigBrady.com> | 2023-02-28 13:34:31 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2023-02-28 14:04:16 +0000 |
commit | 5bcc2912e7d7c16d3052a7ed4f0904f72573255e (patch) | |
tree | f6868796e53f6f8c69cedbdf2c9ed1d0aed1c693 | |
parent | fb757fd7d9b82284be50c10e0e6ce2d6e66b70af (diff) | |
download | coreutils-5bcc2912e7d7c16d3052a7ed4f0904f72573255e.tar.gz |
tail: avoid undefined behavior when polling outputs
* src/tail.c (check_output_alive): Only check the returned
events from poll() when it indicates there are events to check.
-rw-r--r-- | src/tail.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/tail.c b/src/tail.c index e2e7f4690..78022fc4b 100644 --- a/src/tail.c +++ b/src/tail.c @@ -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; |