Skip to content

Commit a3aae09

Browse files
refactor(open): trim restate-the-code and dramatic comments
1 parent bc405e4 commit a3aae09

7 files changed

Lines changed: 7 additions & 25 deletions

File tree

cmd/modern/root/open/clipboard.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import (
1111
"github.com/microsoft/go-sqlcmd/internal/pal"
1212
)
1313

14-
// copyPasswordToClipboard copies the current context's password to the clipboard for SQL auth.
15-
// Returns true when a password was actually copied.
14+
// copyPasswordToClipboard returns true when the password was copied.
1615
func copyPasswordToClipboard(user *sqlconfig.User, out *output.Output) bool {
1716
if out == nil || user == nil || user.AuthenticationType != "basic" || user.BasicAuth == nil {
1817
return false
@@ -24,7 +23,6 @@ func copyPasswordToClipboard(user *sqlconfig.User, out *output.Output) bool {
2423
}
2524

2625
if err := pal.CopyToClipboard(password); err != nil {
27-
// Don't fail the launch over a clipboard hiccup; warn and continue.
2826
out.Warn(localizer.Sprintf("Could not copy password to clipboard: %s", err.Error()))
2927
return false
3028
}

internal/pal/clipboard_darwin.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ func copyToClipboard(text string) error {
1515
return cmd.Run()
1616
}
1717

18-
// pbcopyPath returns the canonical macOS pbcopy path so we never pick up an
19-
// attacker-planted pbcopy from PATH while staging the SQL password on the
20-
// clipboard. Falls back to bare "pbcopy" only if the canonical binary is
21-
// missing (non-standard macOS install).
18+
// pbcopyPath pins pbcopy to its canonical path so PATH order can't redirect the SQL password.
2219
func pbcopyPath() string {
2320
const canonical = "/usr/bin/pbcopy"
2421
if _, err := os.Stat(canonical); err == nil {

internal/pal/clipboard_linux.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import (
1212
func copyToClipboard(text string) error {
1313
var attempts []string
1414
tryCmd := func(name string, args ...string) bool {
15-
// Use the resolved absolute path so a later PATH change can't redirect
16-
// the SQL password to a different binary between lookup and exec.
15+
// Pin the resolved path so PATH order can't redirect the SQL password between lookup and exec.
1716
resolved, err := exec.LookPath(name)
1817
if err != nil {
1918
attempts = append(attempts, fmt.Sprintf("%s not found", name))
@@ -38,7 +37,6 @@ func copyToClipboard(text string) error {
3837
return nil
3938
}
4039

41-
// gotext only scans cmd/modern, cmd/sqlcmd, and pkg/sqlcmd, so this stays plain fmt.Errorf.
4240
return fmt.Errorf(
4341
"failed to copy to clipboard; tried xclip, xsel, wl-copy: %s\n"+
4442
"Install one and re-run (use your own judgement on what fits your environment):\n"+

internal/pal/clipboard_windows.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ func copyToClipboard(text string) error {
1616
return cmd.Run()
1717
}
1818

19-
// clipExePath resolves clip.exe under %SystemRoot%\System32 so we never pick
20-
// up an attacker-planted clip.exe from PATH or the working directory while
21-
// copying the SQL password to the clipboard. Falls back through other
22-
// well-known env vars before defaulting to the canonical C:\Windows path so
23-
// we never return a bare "clip.exe" that PATH could resolve.
19+
// clipExePath pins clip.exe to %SystemRoot%\System32 so PATH order can't redirect the SQL password.
2420
func clipExePath() string {
2521
for _, name := range []string{"SystemRoot", "WINDIR"} {
2622
if v := os.Getenv(name); v != "" {

internal/tools/tool/vscode_darwin.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ func (t *VSCode) searchLocations() []string {
2525
app = "Visual Studio Code - Insiders.app"
2626
}
2727
locations = append(locations, filepath.Join("/", "Applications", app))
28-
// Skip the per-user paths when $HOME is empty -- filepath.Join would
29-
// produce a relative "Applications/..." that could match a directory
30-
// in the working directory.
28+
// Skip per-user paths when $HOME is empty: filepath.Join would yield a relative match.
3129
if userProfile != "" {
3230
locations = append(locations,
3331
filepath.Join(userProfile, "Applications", app),

internal/tools/tool/vscode_linux.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ func (t *VSCode) searchLocations() []string {
2424
locations = append(locations,
2525
filepath.Join("/", "usr", "bin", cli),
2626
)
27-
// Skip the per-user path when $HOME is empty -- filepath.Join would
28-
// produce a relative ".local/bin/<cli>" that could match an unintended
29-
// binary in the working directory.
27+
// Skip per-user path when $HOME is empty: filepath.Join would yield a relative match.
3028
if userProfile != "" {
3129
locations = append(locations, filepath.Join(userProfile, ".local", "bin", cli))
3230
}

internal/tools/tool/vscode_windows.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ func vscodeWindowsLocations(build string) []string {
5353
locations = append(locations, filepath.Join(install, exeName))
5454
}
5555

56-
// Tier 3: standard default install directories. Skip any whose base env
57-
// var was empty -- filepath.Join with an empty base yields a relative
58-
// path (e.g. AppData\...\Code.exe) that could match an unintended binary
59-
// in the working directory.
56+
// Tier 3: standard install dirs. Skip when the base env var is empty: filepath.Join would yield a relative match.
6057
if userDir != "" {
6158
locations = append(locations, filepath.Join(userDir, exeName))
6259
}

0 commit comments

Comments
 (0)