Skip to content

Commit

Permalink
backend/kqueue: fix empty udata crash
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
steeve committed Feb 5, 2025
1 parent 31eed4e commit 283a911
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/backend/kqueue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,15 @@ pub const Loop = struct {
// event list to zero length) because it was leading to
// memory corruption we need to investigate.
for (events[0..completed]) |ev| {
const c: *Completion = @ptrFromInt(@as(usize, @intCast(ev.udata)));
// Zero udata values are internal events that we do nothing
// on such as the mach port wakeup.
if (ev.udata == 0) continue;

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

const c: *Completion = @ptrFromInt(@as(usize, @intCast(ev.udata)));

// If EV_ERROR is set, then submission failed for this
// completion. We get the syscall errorcode from data and
// store it.
Expand Down

0 comments on commit 283a911

Please sign in to comment.