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)
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
45204921be
commit
dad28bffd6
+11
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1002,6 +1002,9 @@ int flush_accept(int fd) {
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
if (pollfd.revents & POLLNVAL)
|
||||
return -EBADF;
|
||||
|
||||
if (iteration >= MAX_FLUSH_ITERATIONS)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EBUSY),
|
||||
"Failed to flush connections within " STRINGIFY(MAX_FLUSH_ITERATIONS) " iterations.");
|
||||
|
||||
Reference in New Issue
Block a user