From dad28bffd67692d6c22e0de98ddb0d217c034ec5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 9 Jun 2020 13:40:25 +0200 Subject: 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) --- src/sleep/sleep.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/sleep') diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index fbfddc0262..4f9c23099a 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -271,6 +271,9 @@ static int execute_s2h(const SleepConfig *sleep_config) { tfd = safe_close(tfd); + if (FLAGS_SET(fds.revents, POLLNVAL)) + return log_error_errno(SYNTHETIC_ERRNO(EBADF), "Invalid timer fd to sleep on?"); + if (!FLAGS_SET(fds.revents, POLLIN)) /* We woke up before the alarm time, we are done. */ return 0; -- cgit v1.2.1