Conversation
…, sun_path overflow Bug 1 - LxssHttpProxy.cpp: IPv6 substr extraction used wrong length calculation. substr(openBracket+1, closeBracket-1) is incorrect when openBracket > 0; fixed to substr(openBracket+1, closeBracket-openBracket-1). Also fixed empty-address guard to check closeBracket (not closeBracket-1). Bug 2 - LxssUserSession.cpp: Two instances of reinterpret_cast<HANDLE*> in ScopedMultiRelay construction should be reinterpret_cast<HANDLE> (without the pointer). Other identical callsites in the same file already use the correct cast. Bug 3 - LxssUserSession.cpp: GetLastError() was called unconditionally after CreateFileW, even on success. A stale ERROR_SHARING_VIOLATION from a prior API call could cause a false throw. Fixed to only check GetLastError() when CreateFileW fails (!vhd). Bug 4 - plan9.cpp: sun_path bounds check used > instead of >= leaving no room for null terminator. Also added a post-split check to ensure the child name fits after splitting parent/child for long paths.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes four distinct bugs across three files related to incorrect string operations, type casting, error handling, and bounds checking.
Changes:
- Corrected IPv6 address extraction logic with proper substring bounds
- Fixed HANDLE type casting in relay construction
- Fixed premature GetLastError() call that could report stale errors
- Corrected bounds checking for Unix socket paths to ensure null terminator space
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/windows/service/exe/LxssHttpProxy.cpp | Fixed IPv6 address extraction substring calculation and empty address validation |
| src/windows/service/exe/LxssUserSession.cpp | Fixed HANDLE type casts and moved GetLastError() check to only execute on CreateFileW failure |
| src/linux/init/plan9.cpp | Fixed sun_path bounds check to account for null terminator and added validation after path splitting |
OneBlue
approved these changes
Feb 26, 2026
| return UnsupportedProxyReason::Supported; | ||
| } | ||
| portRemoved = portRemoved.substr(openBracket + 1, closeBracket - 1); | ||
| portRemoved = portRemoved.substr(openBracket + 1, closeBracket - openBracket - 1); |
Collaborator
There was a problem hiding this comment.
I wish there was an easy way to add test coverage for this.
If we ever factor IsUnsupportedProxy() in common I guess we could add coverage for this
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.
LxssHttpProxy.cpp: IPv6 substr extraction used wrong length calculation. substr(openBracket+1, closeBracket-1) is incorrect when openBracket > 0; fixed to substr(openBracket+1, closeBracket-openBracket-1). Also fixed empty-address guard to check closeBracket (not closeBracket-1).
LxssUserSession.cpp: Two instances of reinterpret_cast<HANDLE*> in ScopedMultiRelay construction should be reinterpret_cast (without the pointer). Other identical callsites in the same file already use the correct cast.
LxssUserSession.cpp: GetLastError() was called unconditionally after CreateFileW, even on success. A stale ERROR_SHARING_VIOLATION from a prior API call could cause a false throw. Fixed to only check GetLastError() when CreateFileW fails (!vhd).
plan9.cpp: sun_path bounds check used > instead of >= leaving no room for null terminator. Also added a post-split check to ensure the child name fits after splitting parent/child for long paths.