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>
This commit is contained in:
Alejandro Mery 2021-03-29 00:14:47 +01:00 committed by Kaleb Elwert
parent 3427354935
commit c7b4a1b92e

@ -140,7 +140,10 @@ func (ctx *sshContext) ServerVersion() string {
}
func (ctx *sshContext) RemoteAddr() net.Addr {
return ctx.Value(ContextKeyRemoteAddr).(net.Addr)
if addr, ok := ctx.Value(ContextKeyRemoteAddr).(net.Addr); ok {
return addr
}
return nil
}
func (ctx *sshContext) LocalAddr() net.Addr {