Skip to content

Small fixes in the session event callbacks #78

Closed

Description

@HEnquist

Two small issues in the IAudioSessionEvents handlers in src/events.rs.

https://github.com/HEnquist/wasapi-rs/blob/7afc1c7/src/events.rs#L228-L312

Unchecked dereference of eventcontext

The handlers read the event context with unsafe { *eventcontext } and never check it for null.
This happens in OnDisplayNameChanged, OnIconPathChanged, OnSimpleVolumeChanged, OnChannelVolumeChanged and OnGroupingParamChanged.
OnGroupingParamChanged does the same with newgroupingparam.

The SetDisplayName docs say that if the caller passes NULL as the event context, the notification method receives a NULL context pointer.
The volume setters say the same.
Any process that changes the session with a NULL context could then hit a null dereference in our callback.

In practice, Windows 11 delivered a pointer to GUID_NULL, not a NULL pointer, when SetDisplayName was called with a NULL context from the same process.
That doesn't make the docs wrong for every caller or Windows version, though.

Fix: read the pointers with something like unsafe { eventcontext.as_ref() }.copied().unwrap_or_default(), so a null pointer becomes GUID_NULL.

Spurious warning in OnChannelVolumeChanged

When changedchannel is u32::MAX (more than one channel changed), the callback runs for every channel as it should.
The code then falls through to the bounds check on changedchannel and logs "received unsupported changedchannel value".
That branch should return after the loop.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions