-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wshless Connections in Wsl #1769
Conversation
WalkthroughThe pull request introduces modifications across multiple packages to enhance the handling of Windows Subsystem for Linux (WSL) shell processes and connection management. In the The These changes collectively enhance the reliability and flexibility of WSL connection and shell process management. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (3)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
pkg/shellexec/shellexec.go (2)
153-172
: Add documentation for the new function.The function needs documentation to explain its purpose, parameters, and return values. Also, consider documenting the differences between this and
StartWslShellProc
.Add this documentation before the function:
+// StartWslShellProcNoWsh starts a WSL shell process without using WSH (Windows Shell). +// This provides a fallback mechanism when WSH is disabled or unavailable. +// +// Parameters: +// - ctx: Context for the operation +// - termSize: Terminal dimensions +// - cmdStr: Command to execute (optional) +// - cmdOpts: Command options including environment variables +// - conn: WSL connection instance +// +// Returns a ShellProc instance and any error encountered.
159-165
: Consider extracting terminal size validation.The terminal size validation logic is duplicated across multiple functions in this file.
Extract into a shared helper function:
+func validateTermSize(termSize waveobj.TermSize) (waveobj.TermSize, error) { + if termSize.Rows == 0 || termSize.Cols == 0 { + termSize.Rows = shellutil.DefaultTermRows + termSize.Cols = shellutil.DefaultTermCols + } + if termSize.Rows <= 0 || termSize.Cols <= 0 { + return termSize, fmt.Errorf("invalid term size: %v", termSize) + } + return termSize, nil +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
pkg/blockcontroller/blockcontroller.go
(1 hunks)pkg/shellexec/shellexec.go
(1 hunks)pkg/wshrpc/wshserver/wshserver.go
(1 hunks)pkg/wslconn/wslconn.go
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
- GitHub Check: Build for TestDriver.ai
🔇 Additional comments (5)
pkg/shellexec/shellexec.go (1)
157-157
: Verify command string escaping.The command construction might be vulnerable to command injection if
client.Name()
contains special characters.Run this script to check for potential command injection vulnerabilities:
✅ Verification successful
Command construction is properly secured against injection
The implementation is safe because:
- WSL distribution names are validated through multiple layers before reaching exec.Command
- Names must match registered WSL distributions
- Go's exec.Command automatically handles argument escaping without shell interpretation
- Invalid distribution names are explicitly filtered out
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check if client.Name() is properly escaped in wsl.exe command construction # Test: Search for wsl.exe command construction patterns. Expect: Proper escaping of arguments. rg -A 2 'wsl\.exe.*-d.*Name\(\)'Length of output: 487
Script:
#!/bin/bash # Find the implementation of Name() method and WSL client interface ast-grep --pattern 'type $_ interface { $$$ Name() string $$$ }' # Also search for any struct implementing Name() ast-grep --pattern 'func ($_ $_) Name() string { $$$ }' # Look for any validation or sanitization of WSL distribution names rg -i "distribution.*name|wsl.*name" -A 3Length of output: 12023
pkg/wslconn/wslconn.go (2)
104-111
: LGTM! Thread-safe status derivation.The use of atomic operations for
WshEnabled
status and addition of WSH-related fields improves thread safety and error tracking.
708-710
: LGTM! Proper nil check.Early return for nil
ConnController
prevents potential panic from nil pointer dereference.pkg/blockcontroller/blockcontroller.go (1)
391-407
: LGTM! Robust fallback mechanism for WSL shell processes.The implementation provides a clean fallback mechanism when WSH is disabled or fails, with proper error handling and status updates.
pkg/wshrpc/wshserver/wshserver.go (1)
786-795
: LGTM! Clean implementation of WSH failure dismissal.The implementation properly handles both WSL and non-WSL connections with appropriate error handling and status updates.
This makes it possible to disable wsh for WSL connections. While this is not recommended, it brings the code closer to the SSH connection implementation and will make it easier to consolidate the two in the future.