Skip to content

Commit 6742515

Browse files
committed
Reply with error code 255 and add explicit returns
1 parent 40b0a4f commit 6742515

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

ssh_session.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func createSSHSessionHandler(shell string) ssh.Handler {
4343
// We use StdinPipe to avoid blocking on missing input
4444
if stdin, err := cmd.StdinPipe(); err != nil {
4545
log.Println("Could not initialize stdinPipe", err)
46-
s.Exit(1)
46+
s.Exit(255)
4747
return
4848
} else {
4949
go func() {
@@ -65,10 +65,12 @@ func createSSHSessionHandler(shell string) ssh.Handler {
6565
if err != nil {
6666
log.Println("Command execution failed:", err)
6767
io.WriteString(s, "Command execution failed: "+err.Error()+"\n")
68-
} else {
69-
log.Println("Command execution successful")
68+
s.Exit(255)
69+
return
7070
}
71+
log.Println("Command execution successful")
7172
s.Exit(cmd.ProcessState.ExitCode())
73+
return
7274

7375
case <-s.Context().Done():
7476
log.Printf("Session terminated: %s", s.Context().Err())

ssh_session_unix.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ func createPty(s ssh.Session, shell string) {
5757
case err := <-done:
5858
if err != nil {
5959
log.Println("Session ended with error:", err)
60-
} else {
61-
log.Println("Session ended normally")
60+
s.Exit(255)
61+
return
6262
}
63+
log.Println("Session ended normally")
6364
s.Exit(cmd.ProcessState.ExitCode())
65+
return
6466

6567
case <-s.Context().Done():
6668
log.Printf("Session terminated: %s", s.Context().Err())

ssh_session_windows.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func createPty(s ssh.Session, shell string) {
4646
io.WriteString(s, "No ConPTY shell or ssh-shellhost enhanced shell available. "+
4747
"Please append 'cmd' to your ssh command to gain shell access, i.e. "+
4848
"'ssh <OPTIONS> <IP> cmd'.\n")
49-
s.Exit(1)
49+
s.Exit(255)
5050
return
5151
}
5252
log.Println("Launching shell with ssh-shellhost.exe")
@@ -60,7 +60,7 @@ func createPty(s ssh.Session, shell string) {
6060
// We use StdinPipe to avoid blocking on missing input
6161
if stdin, err := cmd.StdinPipe(); err != nil {
6262
log.Println("Could not initialize stdinPipe", err)
63-
s.Exit(1)
63+
s.Exit(255)
6464
return
6565
} else {
6666
go func() {
@@ -80,10 +80,12 @@ func createPty(s ssh.Session, shell string) {
8080
case err := <-done:
8181
if err != nil {
8282
log.Println("Session ended with error:", err)
83-
} else {
84-
log.Println("Session ended normally")
83+
s.Exit(255)
84+
return
8585
}
86+
log.Println("Session ended normally")
8687
s.Exit(cmd.ProcessState.ExitCode())
88+
return
8789

8890
case <-s.Context().Done():
8991
log.Printf("Session terminated: %s", s.Context().Err())
@@ -144,11 +146,12 @@ func createPty(s ssh.Session, shell string) {
144146
case result := <-done:
145147
if result.error != nil {
146148
log.Println("Error waiting for process:", err)
147-
s.Exit(1)
149+
s.Exit(255)
148150
return
149151
}
150152
log.Printf("Session ended normally, exit code %d", result.ProcessState.ExitCode())
151153
s.Exit(result.ProcessState.ExitCode())
154+
return
152155

153156
case <-s.Context().Done():
154157
log.Printf("Session terminated: %s", s.Context().Err())

0 commit comments

Comments
 (0)