Skip to content

Fix batch of minor bugs#40197

Open
chemwolf6922 wants to merge 42 commits intomasterfrom
user/chemwolf6922/bug-hunting
Open

Fix batch of minor bugs#40197
chemwolf6922 wants to merge 42 commits intomasterfrom
user/chemwolf6922/bug-hunting

Conversation

@chemwolf6922
Copy link
Copy Markdown
Contributor

Summary of the Pull Request

This PR fixes a batch of minor bugs / issues found during code review.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

@chemwolf6922 chemwolf6922 requested a review from a team as a code owner April 16, 2026 10:46
Copilot AI review requested due to automatic review settings April 16, 2026 10:46
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 applies a set of small correctness fixes across Windows and Linux components of the WSL codebase, primarily addressing copy/paste mistakes, boundary conditions, and API return-value handling.

Changes:

  • Fixes multiple control-flow and boundary-condition issues (missing break, off-by-one in wait result checks, fallthrough in parsers).
  • Corrects API usage/return-value checks and formatting (Win32 BOOL vs HRESULT, pthread/getpwuid_r/getgrnam_r semantics, logging format strings).
  • Improves robustness/clarity in shared utilities (hostname truncation ordering, safer MessageWriter index bounds check, configfile parsing logic).

Reviewed changes

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

Show a summary per file
File Description
src/windows/service/exe/WslCoreVm.cpp Adds missing break in port tracker switch to avoid unintended fallthrough.
src/windows/service/exe/LxssUserSession.cpp Fixes ExecutionContext to use Context::MountDisk for MountDisk.
src/windows/service/exe/DistributionRegistration.cpp Removes duplicate registry write of Property::Flags.
src/windows/common/relay.cpp Fixes off-by-one check for WaitForMultipleObjects results.
src/windows/common/helpers.cpp Fixes off-by-one wait result handling; fixes timezone string resizing to use returned size.
src/windows/common/WslCoreNetworkingSupport.cpp Fixes dynamic function loading to load into the correct function objects.
src/windows/common/HandleConsoleProgressBar.cpp Fixes GetFileSizeEx failure handling (BOOL-returning API, not HRESULT).
src/shared/inc/stringshared.h Ensures cleaned hostname is truncated before trailing ./- trimming and default handling.
src/shared/inc/message.h Reworks relative-index bounds validation and removes unused member.
src/shared/configfile/configfile.cpp Fixes malformed-quote handling logic when overwriting/removing keys during config update.
src/linux/plan9/p9util.cpp Fixes getpwuid_r/getgrnam_r error checks to match their return convention.
src/linux/plan9/p9readdir.cpp Adds missing semicolon after THROW_LAST_ERROR_IF.
src/linux/plan9/p9io.cpp Simplifies AIO callback result computation and aligns aio_write error return sign (but see review comment).
src/linux/plan9/p9file.h Fixes getpwuid_r error check in Root initialization.
src/linux/netlinkutil/NetlinkMessage.hxx Fixes attribute bounds error message to reference sizeof(TAttribute).
src/linux/netlinkutil/Interface.cpp Fixes IFNAMSIZ boundary; avoids writing NUL terminator into sysctl-style procfs values.
src/linux/mountutil/mountutil.c Adds missing break to prevent switch fallthrough after parsing device field.
src/linux/init/wslinfo.cpp Corrects header comment to refer to wslinfo (but see review comment).
src/linux/init/util.cpp Fixes early return on failed accept4; removes unreachable/incorrect loop error handling.
src/linux/init/plan9.cpp Fixes log formatting for setrlimit output.
src/linux/init/main.cpp Fixes pthread return check, initialization, variable shadowing, sockaddr initialization, and parsing condition.
src/linux/init/config.cpp Fixes log formatting for buffer size output.
src/linux/init/SecCompDispatcher.cpp Fixes log formatting specifiers/types for seccomp notification logging.
src/linux/init/DnsServer.cpp Removes redundant/overwritten epoll_event.data.fd assignment when using data.ptr.
src/linux/inc/lxwil.h Fixes pipe2 error check condition.

Comment thread src/linux/plan9/p9io.cpp
Comment thread src/linux/init/wslinfo.cpp Outdated
Copy link
Copy Markdown
Collaborator

@OneBlue OneBlue left a comment

Choose a reason for hiding this comment

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

Lots of great fixes in there, looks great ! Couple minor questions

Comment thread src/linux/init/main.cpp
Comment thread src/linux/init/util.cpp Outdated
Comment thread src/linux/init/util.cpp
Comment thread src/linux/plan9/p9io.cpp
Comment thread src/shared/inc/message.h Outdated
Copilot AI review requested due to automatic review settings April 17, 2026 02:55
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

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

src/linux/plan9/p9util.cpp:169

  • getpwuid_r() returns an error number directly; this loop checks errno != ERANGE to decide whether to grow the buffer. That relies on errno being set, which isn’t guaranteed by the API contract. Capture the return value from getpwuid_r() and compare it to ERANGE instead (and use that same return value for the non-ERANGE error path).
        if (getpwuid_r(uid, &pwd, buffer.data(), size, &result) != 0)
        {
            if (errno != ERANGE)
            {
                return c_InvalidGid;

src/linux/plan9/p9util.cpp:205

  • getgrnam_r() returns an error number directly; the ERANGE retry logic should check the function’s return value rather than errno to decide whether to resize/retry. This avoids relying on errno being set by the implementation.
        if (getgrnam_r(name, &grp, buffer.data(), size, &result) != 0)
        {
            if (errno != ERANGE)
            {
                return c_InvalidGid;

Comment thread src/linux/plan9/p9io.cpp
Copilot AI review requested due to automatic review settings April 17, 2026 08:10
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

Copilot reviewed 33 out of 33 changed files in this pull request and generated 1 comment.

Comment thread src/shared/configfile/configfile.cpp Outdated
benhillis pushed a commit that referenced this pull request Apr 17, 2026
Bugs fixed (not covered by PR #40197):
- unittests.c: Fix get_addr_info test entry pointing to wrong handler
  (GetSetIdTestEntry -> GetAddrInfoTestEntry)
- SocketChannel.h: Fix %s format specifier in fmt-style LOG_ERROR on
  Linux; channel name was silently dropped from protocol error logs
- p9file.cpp: Fix readlinkat return type (int -> ssize_t) to match
  POSIX specification
- configfile.cpp: Guard ungetwc() call against WEOF to avoid undefined
  behavior on some implementations
- init.cpp: Fix SIGCHLD race by blocking the signal before setting the
  handler, preventing a window where child exit could be lost
- util.cpp: Extract duplicated signal skip list into SkipSignal() helper
  to ensure consistency between save and set handlers

Test improvements:
- NetworkTests.cpp: Add SO_RCVTIMEO timeout on accept() to prevent
  indefinite test hangs (resolves TODO)
- DrvFsTests.cpp: Add LOG_IF_WIN32_BOOL_FALSE to cleanup operations
  to surface silent file/directory deletion failures

Script hardening:
- copy_and_build_tests.ps1: Replace Invoke-Expression with call operator
  to prevent command injection via interpolated variables
- test-setup.ps1: Pass PostInstallCommand through bash -c for proper
  shell argument handling
- deploy-to-vm.ps1: Prompt for password via Read-Host -AsSecureString
  when not provided, instead of creating empty SecureString

Resource management:
- WslConfigService.cs: Dispose FileSystemWatcher in destructor to
  prevent resource leak

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
benhillis pushed a commit that referenced this pull request Apr 17, 2026
Full deep review covering 7 subsystems with 44 findings.
12 fixes on this branch, 10+ already in PR #40197, 4 deferred.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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