Skip to content

Commit 2fa8443

Browse files
committed
Fixes 198, and stops a nil pointer exception
1 parent 614f154 commit 2fa8443

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

internal/client/handlers/remoteforward.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,19 @@ func handleData(rf internal.RemoteForwardRequest, proxyCon net.Conn, sshConn ssh
132132

133133
drtMsg := internal.ChannelOpenDirectMsg{
134134

135-
Raddr: originatorAddress,
136-
Rport: uint32(originatorPortInt),
135+
Raddr: rf.BindAddr,
136+
Rport: rf.BindPort,
137137

138-
Laddr: rf.BindAddr,
139-
Lport: rf.BindPort,
138+
Laddr: originatorAddress,
139+
Lport: uint32(originatorPortInt),
140140
}
141141

142-
log.Printf("formed drtMsg: %+v", drtMsg)
143-
144142
b := ssh.Marshal(&drtMsg)
145143

146144
source, reqs, err := sshConn.OpenChannel("forwarded-tcpip", b)
147145
if err != nil {
148146
log.Println("Opening forwarded-tcpip channel to server failed: ", err)
149147

150-
return err
151148
}
152149
defer source.Close()
153150

internal/client/handlers/session.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,16 @@ func Session(session *connection.Session) func(newChannel ssh.NewChannel, log lo
9696
}
9797
}
9898

99+
argv := ""
100+
if u != nil {
101+
argv = u.Query().Get("argv")
102+
}
103+
99104
if session.Pty != nil {
100-
runCommandWithPty(u.Query().Get("argv"), command, line.Chunks[1:], session.Pty, requests, log, connection)
105+
runCommandWithPty(argv, command, line.Chunks[1:], session.Pty, requests, log, connection)
101106
return
102107
}
103-
runCommand(u.Query().Get("argv"), command, line.Chunks[1:], connection)
108+
runCommand(argv, command, line.Chunks[1:], connection)
104109

105110
return
106111
case "shell":
@@ -128,7 +133,12 @@ func Session(session *connection.Session) func(newChannel ssh.NewChannel, log lo
128133
}
129134
}
130135

131-
runCommandWithPty(u.Query().Get("argv"), command, parts[1:], session.Pty, requests, log, connection)
136+
argv := ""
137+
if u != nil {
138+
argv = u.Query().Get("argv")
139+
}
140+
141+
runCommandWithPty(argv, command, parts[1:], session.Pty, requests, log, connection)
132142
}
133143
return
134144
//Yes, this is here for a reason future me. Despite the RFC saying "Only one of shell,subsystem, exec can occur per channel" pty-req actually proceeds all of them
@@ -198,7 +208,7 @@ func runCommand(argv string, command string, args []string, connection ssh.Chann
198208
func isUrl(data string) (*url.URL, bool) {
199209
u, err := url.Parse(data)
200210
if err != nil {
201-
return u, false
211+
return nil, false
202212
}
203213

204214
switch u.Scheme {

0 commit comments

Comments
 (0)