summaryrefslogtreecommitdiff
path: root/src/stdio-bridge
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-06-09 13:40:25 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-06-10 08:57:31 +0200
commitdad28bffd67692d6c22e0de98ddb0d217c034ec5 (patch)
tree29b5ec4a723341c4a38636d8be4566dba5a38ec0 /src/stdio-bridge
parent45204921be610be839482a037985fd5a5052f2dd (diff)
downloadsystemd-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/stdio-bridge')
-rw-r--r--src/stdio-bridge/stdio-bridge.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/stdio-bridge/stdio-bridge.c b/src/stdio-bridge/stdio-bridge.c
index 52b9ce4555..ca145aebf9 100644
--- a/src/stdio-bridge/stdio-bridge.c
+++ b/src/stdio-bridge/stdio-bridge.c
@@ -238,17 +238,19 @@ static int run(int argc, char *argv[]) {
ts = timespec_store(&_ts, t);
}
- {
- struct pollfd p[3] = {
- {.fd = fd, .events = events_a },
- {.fd = STDIN_FILENO, .events = events_b & POLLIN },
- {.fd = STDOUT_FILENO, .events = events_b & POLLOUT },
- };
-
- r = ppoll(p, ELEMENTSOF(p), ts, NULL);
- }
+ struct pollfd p[3] = {
+ { .fd = fd, .events = events_a },
+ { .fd = STDIN_FILENO, .events = events_b & POLLIN },
+ { .fd = STDOUT_FILENO, .events = events_b & POLLOUT },
+ };
+
+ r = ppoll(p, ELEMENTSOF(p), ts, NULL);
if (r < 0)
return log_error_errno(errno, "ppoll() failed: %m");
+ if (p[0].revents & POLLNVAL ||
+ p[1].revents & POLLNVAL ||
+ p[2].revents & POLLNVAL)
+ return log_error_errno(SYNTHETIC_ERRNO(EBADF), "Invalid file descriptor to poll on?");
}
return 0;