提交 db939964 编写于 作者: X xuelei

5067458: Loopback SSLSocketImpl createSocket is throwing an exception

Summary: A null hostname should be regarded as a loopback address.
Reviewed-by: weijun
上级 707c32d6
/*
* Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1996-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -368,7 +368,9 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
super();
this.host = host;
init(context, false);
SocketAddress socketAddress = new InetSocketAddress(host, port);
SocketAddress socketAddress =
host != null ? new InetSocketAddress(host, port) :
new InetSocketAddress(InetAddress.getByName(null), port);
connect(socketAddress, 0);
}
......@@ -409,7 +411,9 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
this.host = host;
init(context, false);
bind(new InetSocketAddress(localAddr, localPort));
SocketAddress socketAddress = new InetSocketAddress(host, port);
SocketAddress socketAddress =
host != null ? new InetSocketAddress(host, port) :
new InetSocketAddress(InetAddress.getByName(null), port);
connect(socketAddress, 0);
}
......@@ -1829,7 +1833,8 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
}
synchronized String getHost() {
if (host == null) {
// Note that the host may be null or empty for localhost.
if (host == null || host.length() == 0) {
host = getInetAddress().getHostName();
}
return host;
......
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 5067458
* @summary Loopback SSLSocketImpl createSocket is throwing an exception.
* @author Xuelei Fan
*/
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
public class LoopbackSSLSocket {
public static void main(String[] args) throws Exception {
SSLSocketFactory sf = (SSLSocketFactory)SSLSocketFactory.getDefault();
// we won't expect a IllegalArgumentException: hostname can't be null.
try {
SSLSocket s = (SSLSocket)sf.createSocket((String)null, 0);
s.close();
} catch (IOException ioe) {
// would catch a IOException because there is no listener on
// that socket.
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册