Repository navigation
Avoid Winsock provider loading for local hostname lookups - #892
Open
Steve Lee (SteveL-MSFT) wants to merge 1 commit into
Open
Steve Lee (SteveL-MSFT) wants to merge 1 commit into
Steve Lee (SteveL-MSFT) wants to merge 1 commit into
Conversation
Use GetComputerNameExW with UTF-8 conversion and retain Winsock as a fallback. Validate buffer sizes and add hostname regression coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the Windows hostname-lookup change.
No open issues 🎉
What changed in this PR
This PR updates the Windows compatibility layer to avoid unnecessary Winsock namespace-provider loading during local hostname lookups, reducing startup work for ssh-keygen.
Changes:
- Uses
GetComputerNameExWwith stack-based UTF-8 conversion, retaining Winsock as a fallback. - Reports invalid and insufficient buffers through
errno. - Adds regression checks for hostname equality, exact-fit buffers, invalid buffers, and additional
dnsapi.dllloading.
The reported focused harness passed; the full repository build and unit suite remain unverified.
| File | Description |
|---|---|
regress/unittests/win32compat/socket_tests.c |
Adds hostname, buffer-boundary, error, and provider-loading checks. |
contrib/win32/win32compat/socketio.c |
Implements native hostname retrieval, UTF-8 conversion, and Winsock fallback. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Local hostname lookup currently invokes Winsock, loading network namespace providers unnecessarily during ssh-keygen startup.
Use
GetComputerNameExW(ComputerNameDnsHostname)and convert the result to UTF-8 without heap allocation. Retain Winsock as a fallback if the native lookup fails, and report invalid or insufficient buffers througherrno. Add regression checks for hostname equality, exact-fit buffers, invalid buffers, and avoiding additional DNS provider loading.Validation: A focused harness compiled the exact production function with VS 2022
/W4 /WXand passed native hostname, provider-loading, UTF-8 boundary, fallback, and error-mapping checks. The full repository build and unit suite remain unverified because the required VS 2026 ARM64 tools are unavailable on this machine.Fixes PowerShell/Win32-OpenSSH#2493