Skip to content

Check WSLCHandle discriminant before accessing union member#40329

Open
benhillis wants to merge 1 commit intofeature/wsl-for-appsfrom
copilot/fix-h6-union-discriminant
Open

Check WSLCHandle discriminant before accessing union member#40329
benhillis wants to merge 1 commit intofeature/wsl-for-appsfrom
copilot/fix-h6-union-discriminant

Conversation

@benhillis
Copy link
Copy Markdown
Member

DmesgOutput is a discriminated union (WSLCHandle). Accessing Handle.File without verifying Type == WSLCHandleTypeFile is undefined behavior when the active member is Pipe or Socket. Adds the type check before accessing the File member.

DmesgOutput is a discriminated union (WSLCHandle). Accessing
Handle.File without verifying Type == WSLCHandleTypeFile is
undefined behavior when the active member is Pipe or Socket.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 25, 2026 21:07
@benhillis benhillis requested a review from a team as a code owner April 25, 2026 21:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes undefined behavior in the Windows service VM initialization path by ensuring WSLCHandle’s discriminant is checked before reading the Handle.File union member when wiring up the optional dmesg output handle.

Changes:

  • Guard access to Settings->DmesgOutput.Handle.File by checking Settings->DmesgOutput.Type == WSLCHandleTypeFile first.
  • Prevent invalid/undefined reads of the WSLCHandle union when the active member is Pipe or Socket.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants