Don't NPE in SSH keys panel when SSHD is bound to localhost
If the SSHD was bound to 127.0.0.1 (aka localhost), such as might be done on a developer workstation, don't crash out with an NPE on the server side when the client requests the server host keys. Instead try to return the host keys using that 127.0.0.1 address, and if we really don't have a name for our SSHD, don't return any host keys at all, as there is no reasonable way for the client to contact us. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -87,6 +87,11 @@ class SystemInfoServiceImpl implements SystemInfoService {
|
||||
|
||||
public void daemonHostKeys(final AsyncCallback<List<SshHostKey>> callback) {
|
||||
final String hostIdent = hostIdent();
|
||||
if (hostIdent == null) {
|
||||
callback.onSuccess(Collections.<SshHostKey> emptyList());
|
||||
return;
|
||||
}
|
||||
|
||||
final ArrayList<SshHostKey> r = new ArrayList<SshHostKey>(hostKeys.size());
|
||||
for (final PublicKey pub : hostKeys) {
|
||||
try {
|
||||
@@ -132,6 +137,10 @@ class SystemInfoServiceImpl implements SystemInfoService {
|
||||
|
||||
private String hostIdent() {
|
||||
InetSocketAddress addr = sshd.getAddress();
|
||||
if (addr == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InetAddress ip = addr.getAddress();
|
||||
if (ip.isAnyLocalAddress()) {
|
||||
try {
|
||||
|
||||
@@ -245,6 +245,17 @@ public class SshDaemon extends SshServer implements SshInfo {
|
||||
}
|
||||
return inetAddr;
|
||||
}
|
||||
|
||||
// No non-loopback address available? Try any address then.
|
||||
//
|
||||
for (final SocketAddress addr : listen) {
|
||||
if (addr instanceof InetSocketAddress) {
|
||||
return (InetSocketAddress) addr;
|
||||
}
|
||||
}
|
||||
|
||||
// We give up, with no valid address.
|
||||
//
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user