Skip to content

Commit 283a911

Browse files
committed
backend/kqueue: fix empty udata crash
On certain occasions, internal kqueue events are dispatched with an empty udata field. This causes a crash when trying to access the udata field in the event handler. This patch adds a check to ensure that the udata field is not empty before accessing it just like in the other events consumer.
1 parent 31eed4e commit 283a911

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/backend/kqueue.zig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,15 @@ pub const Loop = struct {
206206
// event list to zero length) because it was leading to
207207
// memory corruption we need to investigate.
208208
for (events[0..completed]) |ev| {
209-
const c: *Completion = @ptrFromInt(@as(usize, @intCast(ev.udata)));
209+
// Zero udata values are internal events that we do nothing
210+
// on such as the mach port wakeup.
211+
if (ev.udata == 0) continue;
210212

211213
// We handle deletions separately.
212214
if (ev.flags & posix.system.EV_DELETE != 0) continue;
213215

216+
const c: *Completion = @ptrFromInt(@as(usize, @intCast(ev.udata)));
217+
214218
// If EV_ERROR is set, then submission failed for this
215219
// completion. We get the syscall errorcode from data and
216220
// store it.

0 commit comments

Comments
 (0)