From 1f9a99a8055c92dc27ee99e1a9680fbb1c752190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 19 May 2020 22:52:23 +0200 Subject: [PATCH] Fix potential access of an invalid waiter queue. --- source/eventcore/drivers/posix/events.d | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/eventcore/drivers/posix/events.d b/source/eventcore/drivers/posix/events.d index 791907b..00631c3 100644 --- a/source/eventcore/drivers/posix/events.d +++ b/source/eventcore/drivers/posix/events.d @@ -114,6 +114,10 @@ final class PosixEventDriverEvents(Loop : PosixEventLoop, Sockets : EventDriverS { if (!isValid(event)) return; + // make sure the event stays alive until all waiters have been notified. + addRef(event); + scope (exit) releaseRef(event); + auto slot = getSlot(event); if (notify_all) { //log("emitting only for this thread (%s waiters)", m_fds[event].waiters.length); @@ -167,9 +171,12 @@ final class PosixEventDriverEvents(Loop : PosixEventLoop, Sockets : EventDriverS trigger(event, cnt > 0); } } else { - private void onSocketData(DatagramSocketFD s, IOStatus, size_t, scope RefAddress) + private void onSocketData(DatagramSocketFD s, IOStatus st, size_t, scope RefAddress) @nogc { - m_sockets.receiveNoGC(s, m_buf, IOMode.once, &onSocketData); + // avoid infinite recursion in case of errors + if (st == IOStatus.ok) + m_sockets.receiveNoGC(s, m_buf, IOMode.once, &onSocketData); + try { EventID evt = m_sockets.userData!EventID(s); scope doit = {