blob: 1fc90408216380ffa57f4c2a103ea604e2c9b2c3 [file] [log] [blame]
From 14fd39c9753ce0ccc44d4e9cc2b091af06e16a6b Mon Sep 17 00:00:00 2001
From: Andrzej Ostruszka <amo@semihalf.com>
Date: Mon, 12 Apr 2021 16:18:55 +0000
Subject: [PATCH] Check read callbacks before execution
Since all file descriptors are marked POLLIN but read_cb argument of
eloop_event_add() function can be NULL we need to check read_cb before
we execute it.
---
eloop.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/eloop.c b/eloop.c
index e479ac1..9d63a46 100644
--- a/eloop.c
+++ b/eloop.c
@@ -611,10 +611,10 @@ eloop_start(struct eloop_ctx *ctx)
continue;
}
e = (struct eloop_event *)ke.udata;
- if (ke.filter == EVFILT_WRITE) {
+ if (ke.filter == EVFILT_WRITE && e->write_cb) {
e->write_cb(e->write_cb_arg);
continue;
- } else if (ke.filter == EVFILT_READ) {
+ } else if (ke.filter == EVFILT_READ && e->read_cb) {
e->read_cb(e->read_cb_arg);
continue;
}
@@ -627,7 +627,8 @@ eloop_start(struct eloop_ctx *ctx)
continue;
}
if (epe.events &
- (EPOLLIN | EPOLLERR | EPOLLHUP))
+ (EPOLLIN | EPOLLERR | EPOLLHUP) &&
+ e->read_cb)
{
e->read_cb(e->read_cb_arg);
continue;
@@ -642,7 +643,10 @@ eloop_start(struct eloop_ctx *ctx)
e->write_cb(e->write_cb_arg);
break;
}
- if (e->pollfd->revents) {
+ if (e->pollfd->revents &
+ (POLLIN | POLLERR | POLLHUP) &&
+ e->read_cb)
+ {
e->read_cb(e->read_cb_arg);
break;
}
--
2.31.1.295.g9ea45b61b8-goog