Skip to content

Commit c7b4a1b

Browse files
amerybelak
authored andcommitted
Prevent Context.RemoteAddr() from exploding when called from ConnCallback
When calling ctx.RemoteAddr() within ConnCallback one gets a panic due to unsafe casting within the accessor. I understand it's not a valid scenario as such, but I accidentally called a logger that expected that checked for RemoteAddr() in ssh.Context panic: interface conversion: interface is nil, not net.Addr Signed-off-by: Alejandro Mery <amery@geeks.cl>
1 parent 3427354 commit c7b4a1b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

context.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ func (ctx *sshContext) ServerVersion() string {
140140
}
141141

142142
func (ctx *sshContext) RemoteAddr() net.Addr {
143-
return ctx.Value(ContextKeyRemoteAddr).(net.Addr)
143+
if addr, ok := ctx.Value(ContextKeyRemoteAddr).(net.Addr); ok {
144+
return addr
145+
}
146+
return nil
144147
}
145148

146149
func (ctx *sshContext) LocalAddr() net.Addr {

0 commit comments

Comments
 (0)