Skip to content

Commit e151940

Browse files
committed
pkg/sshutil: Fix SSHOptsRemovingControlPath() to avoid changing the original opts
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
1 parent 2171b0a commit e151940

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pkg/sshutil/sshutil.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ func SSHArgsFromOpts(opts []string) []string {
373373

374374
// SSHOptsRemovingControlPath removes ControlMaster, ControlPath, and ControlPersist options from SSH options.
375375
func SSHOptsRemovingControlPath(opts []string) []string {
376-
return slices.DeleteFunc(opts, func(s string) bool {
376+
// Create a copy of opts to avoid modifying the original slice, since slices.DeleteFunc modifies the slice in place.
377+
copiedOpts := slices.Clone(opts)
378+
return slices.DeleteFunc(copiedOpts, func(s string) bool {
377379
return strings.HasPrefix(s, "ControlMaster") || strings.HasPrefix(s, "ControlPath") || strings.HasPrefix(s, "ControlPersist")
378380
})
379381
}

0 commit comments

Comments
 (0)