Skip to content

Make sure that message structures are correctly zero-initialized - #41373

Merged
Ben Hillis (benhillis) merged 2 commits into
masterfrom
zero-init-message-structs
Aug 18, 2026
Merged

Ben Hillis (benhillis) merged 2 commits into
masterfrom
zero-init-message-structs

Conversation

@benhillis

Copy link
Copy Markdown
Member

Several message structures were declared without value-initialization before their fields were assigned, so any field not explicitly set (and any padding, for the aggregate types) started out indeterminate rather than zeroed.

This adds {} at the declaration so the structures are consistently zero-initialized before use, matching the pattern already used elsewhere (e.g. LX_INIT_CREATE_PROCESS_RESPONSE in interop.cpp and LX_INIT_WINDOW_SIZE_CHANGED in svccomm.cpp).

No behavioral change is intended; every field that was previously assigned is still assigned.

Several message structures were declared without value-initialization
before their fields were assigned. Use {} consistently at the
declaration so the structures start out zeroed.

Co-authored-by: Copilot <[email protected]>
Copilot AI lite review requested due to automatic review settings August 18, 2026 17:30
@benhillis
Ben Hillis (benhillis) requested review from a team as code owners August 18, 2026 17:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 aims to make message structs used in WSL’s init/mini_init and WSLC channel transactions start from a known-zero state by adding {} at declaration sites, reducing the risk of sending indeterminate data when not all fields are explicitly assigned.

Changes:

  • Added {} value-initialization to several WSLC message instances before fields are populated and sent.
  • Added {} value-initialization to init/mini_init message structs on both Windows and Linux paths.
  • Applied the same pattern in interop paths where exit-status messages are constructed and sent.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/windows/wslcsession/WSLCVirtualMachine.cpp Value-initialize several WSLC request messages before populating fields and calling Transaction().
src/windows/wslcsession/DockerHTTPClient.cpp Value-initialize WSLC_FORK before sending the fork request over the channel.
src/windows/service/exe/WslCoreVm.cpp Value-initialize mini_init message structs prior to setting header/payload fields.
src/windows/common/interop.cpp Value-initialize LX_INIT_PROCESS_EXIT_STATUS prior to setting header/payload fields.
src/linux/init/util.cpp Value-initialize MESSAGE_HEADER before setting message type/size for queries.
src/linux/init/main.cpp Value-initialize LX_MINI_INIT_MOUNT_RESULT_MESSAGE prior to setting header/result fields.
src/linux/init/init.cpp Value-initialize session/exit-status response structs before setting fields.
src/linux/init/drvfs.cpp Value-initialize MESSAGE_HEADER for the drvfs elevated query message.
src/linux/init/binfmt.cpp Value-initialize reply/resize structs before use (including a local aggregate Reply).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/windows/wslcsession/WSLCVirtualMachine.cpp Outdated
Comment thread src/windows/wslcsession/DockerHTTPClient.cpp Outdated
The WSLC_* message types declare a default constructor via DECLARE_MESSAGE_CTOR, so adding {} at the declaration has no effect for them. Limit the change to the aggregate message types, where {} actually initializes the structure.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings August 18, 2026 20:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@benhillis
Ben Hillis (benhillis) enabled auto-merge (squash) August 18, 2026 21:31
@benhillis
Ben Hillis (benhillis) merged commit 5106ffe into master Aug 18, 2026
12 checks passed
@benhillis
Ben Hillis (benhillis) deleted the zero-init-message-structs branch August 18, 2026 22:47
Ben Hillis (benhillis) added a commit that referenced this pull request Sep 9, 2026
) (#41524)

* Make sure that message structures are correctly zero-initialized

Several message structures were declared without value-initialization
before their fields were assigned. Use {} consistently at the
declaration so the structures start out zeroed.

Co-authored-by: Copilot <[email protected]>

* Drop redundant initializers from WSLC message declarations

The WSLC_* message types declare a default constructor via DECLARE_MESSAGE_CTOR, so adding {} at the declaration has no effect for them. Limit the change to the aggregate message types, where {} actually initializes the structure.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Ben Hillis <[email protected]>
Co-authored-by: Copilot <[email protected]>
(cherry picked from commit 5106ffe)

Copilot-Session: 35c940dc-b8de-495b-b9c6-b33f4fa16030
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.

3 participants