diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-06-09 13:40:25 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-06-10 08:57:31 +0200 |
commit | dad28bffd67692d6c22e0de98ddb0d217c034ec5 (patch) | |
tree | 29b5ec4a723341c4a38636d8be4566dba5a38ec0 /src/basic/io-util.c | |
parent | 45204921be610be839482a037985fd5a5052f2dd (diff) | |
download | systemd-dad28bffd67692d6c22e0de98ddb0d217c034ec5.tar.gz |
tree-wide: check POLLNVAL everywhere
poll() sets POLLNVAL inside of the poll structures if an invalid fd is
passed. So far we generally didn't check for that, thus not taking
notice of the error. Given that this specific kind of error is generally
indication of a programming error, and given that our code is embedded
into our projects via NSS or because people link against our library,
let's explicitly check for this and convert it to EBADF.
(I ran into a busy loop because of this missing check when some of my
test code accidentally closed an fd it shouldn't close, so this is a
real thing)
Diffstat (limited to 'src/basic/io-util.c')
-rw-r--r-- | src/basic/io-util.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/basic/io-util.c b/src/basic/io-util.c index c906fc0741..4b3d1c814f 100644 --- a/src/basic/io-util.c +++ b/src/basic/io-util.c @@ -33,10 +33,13 @@ int flush_fd(int fd) { continue; return -errno; - - } else if (r == 0) + } + if (r == 0) return count; + if (pollfd.revents & POLLNVAL) + return -EBADF; + l = read(fd, buf, sizeof(buf)); if (l < 0) { @@ -169,6 +172,9 @@ int pipe_eof(int fd) { if (r == 0) return 0; + if (pollfd.revents & POLLNVAL) + return -EBADF; + return pollfd.revents & POLLHUP; } @@ -188,6 +194,9 @@ int fd_wait_for_event(int fd, int event, usec_t t) { if (r == 0) return 0; + if (pollfd.revents & POLLNVAL) + return -EBADF; + return pollfd.revents; } |