提交 c3bad3fb 编写于 作者: A asaha

Merge

......@@ -687,4 +687,6 @@ af0e709d28f9124dd2c37069e0bf4c0751248c61 jdk8u131-b05
3c7f99282d1b5e29f7466bf25fb6878bfebfc58a jdk8u131-b06
f5d0aadb4d1ca74eda4e98cc0030f1618ef4c870 jdk8u131-b07
6e362e6002abc39c63fc8ab4bcebf08e273f5a94 jdk8u131-b08
40d00399869d8a28cfecf360234f340e9e0ad3b1 jdk8u131-b09
c0091a673d766ce2e76a945bab6de325fe78dd88 jdk8u131-b10
a160009bbe1417d85f1c0eec890fdb17391b3637 jdk8u141-b00
/*
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. 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
......@@ -517,7 +517,8 @@ public class FtpClient extends sun.net.ftp.FtpClient {
* @return <code>true</code> if the command was successful
* @throws IOException
*/
private boolean issueCommand(String cmd) throws IOException {
private boolean issueCommand(String cmd) throws IOException,
sun.net.ftp.FtpProtocolException {
if (!isConnected()) {
throw new IllegalStateException("Not connected");
}
......@@ -528,6 +529,12 @@ public class FtpClient extends sun.net.ftp.FtpClient {
// ignore...
}
}
if (cmd.indexOf('\n') != -1) {
sun.net.ftp.FtpProtocolException ex
= new sun.net.ftp.FtpProtocolException("Illegal FTP command");
ex.initCause(new IllegalArgumentException("Illegal carriage return"));
throw ex;
}
sendServer(cmd + "\r\n");
return readReply();
}
......@@ -1120,7 +1127,10 @@ public class FtpClient extends sun.net.ftp.FtpClient {
*/
public void close() throws IOException {
if (isConnected()) {
issueCommand("QUIT");
try {
issueCommand("QUIT");
} catch (FtpProtocolException e) {
}
loggedIn = false;
}
disconnect();
......@@ -1898,7 +1908,8 @@ public class FtpClient extends sun.net.ftp.FtpClient {
return null;
}
private boolean sendSecurityData(byte[] buf) throws IOException {
private boolean sendSecurityData(byte[] buf) throws IOException,
sun.net.ftp.FtpProtocolException {
BASE64Encoder encoder = new BASE64Encoder();
String s = encoder.encode(buf);
return issueCommand("ADAT " + s);
......
/*
* Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2017, Oracle and/or its affiliates. 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
......@@ -43,6 +43,7 @@ import sun.net.TransferProtocolClient;
public class SmtpClient extends TransferProtocolClient {
private static int DEFAULT_SMTP_PORT = 25;
String mailhost;
SmtpPrintStream message;
......@@ -74,6 +75,10 @@ public class SmtpClient extends TransferProtocolClient {
}
public void to(String s) throws IOException {
if (s.indexOf('\n') != -1) {
throw new IOException("Illegal SMTP command",
new IllegalArgumentException("Illegal carriage return"));
}
int st = 0;
int limit = s.length();
int pos = 0;
......@@ -116,16 +121,21 @@ public class SmtpClient extends TransferProtocolClient {
}
public void from(String s) throws IOException {
if (s.startsWith("<"))
if (s.indexOf('\n') != -1) {
throw new IOException("Illegal SMTP command",
new IllegalArgumentException("Illegal carriage return"));
}
if (s.startsWith("<")) {
issueCommand("mail from: " + s + "\r\n", 250);
else
} else {
issueCommand("mail from: <" + s + ">\r\n", 250);
}
}
/** open a SMTP connection to host <i>host</i>. */
private void openServer(String host) throws IOException {
mailhost = host;
openServer(mailhost, 25);
openServer(mailhost, DEFAULT_SMTP_PORT);
issueCommand("helo "+InetAddress.getLocalHost().getHostName()+"\r\n", 250);
}
......
......@@ -952,7 +952,11 @@ public class HttpClient extends NetworkClient {
pi.setContentType(responses.findValue("content-type"));
}
if (isKeepingAlive()) {
// If disableKeepAlive == true, the client will not be returned
// to the cache. But we still need to use a keepalive stream to
// allow the multi-message authentication exchange on the connection
boolean useKeepAliveStream = isKeepingAlive() || disableKeepAlive;
if (useKeepAliveStream) {
// Wrap KeepAliveStream if keep alive is enabled.
logFinest("KeepAlive stream used: " + url);
serverInput = new KeepAliveStream(serverInput, pi, cl, this);
......
/*
* Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2016, Oracle and/or its affiliates. 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
......@@ -298,6 +298,13 @@ public class FtpURLConnection extends URLConnection {
// Just keep throwing for now.
throw e;
} catch (FtpProtocolException fe) {
if (ftp != null) {
try {
ftp.close();
} catch (IOException ioe) {
fe.addSuppressed(ioe);
}
}
throw new IOException(fe);
}
try {
......@@ -480,11 +487,34 @@ public class FtpURLConnection extends URLConnection {
msgh.add("content-type", "text/plain");
msgh.add("access-type", "directory");
} catch (IOException ex) {
throw new FileNotFoundException(fullpath);
FileNotFoundException fnfe = new FileNotFoundException(fullpath);
if (ftp != null) {
try {
ftp.close();
} catch (IOException ioe) {
fnfe.addSuppressed(ioe);
}
}
throw fnfe;
} catch (FtpProtocolException ex2) {
throw new FileNotFoundException(fullpath);
FileNotFoundException fnfe = new FileNotFoundException(fullpath);
if (ftp != null) {
try {
ftp.close();
} catch (IOException ioe) {
fnfe.addSuppressed(ioe);
}
}
throw fnfe;
}
} catch (FtpProtocolException ftpe) {
if (ftp != null) {
try {
ftp.close();
} catch (IOException ioe) {
ftpe.addSuppressed(ioe);
}
}
throw new IOException(ftpe);
}
setProperties(msgh);
......
/*
* Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. 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
......
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. 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
......@@ -466,7 +466,9 @@ GetJavaProperties(JNIEnv* env)
* Windows Server 2008 R2 6 1 (!VER_NT_WORKSTATION)
* Windows 8 6 2 (VER_NT_WORKSTATION)
* Windows Server 2012 6 2 (!VER_NT_WORKSTATION)
* Windows Server 2012 R2 6 3 (!VER_NT_WORKSTATION)
* Windows 10 10 0 (VER_NT_WORKSTATION)
* Windows Server 2016 10 0 (!VER_NT_WORKSTATION)
*
* This mapping will presumably be augmented as new Windows
* versions are released.
......@@ -540,6 +542,7 @@ GetJavaProperties(JNIEnv* env)
}
} else {
switch (minorVersion) {
case 0: sprops.os_name = "Windows Server 2016"; break;
default: sprops.os_name = "Windows NT (unknown)";
}
}
......
/*
* Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7167293
* @summary FtpURLConnection doesn't close FTP connection when FileNotFoundException is thrown
* @library ../www/ftptest/
* @build FtpServer FtpCommandHandler FtpAuthHandler FtpFileSystemHandler
* @run main FtpURLConnectionLeak
*/
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
public class FtpURLConnectionLeak {
public static void main(String[] args) throws Exception {
FtpServer server = new FtpServer(0);
server.setFileSystemHandler(new CustomFileSystemHandler("/"));
server.setAuthHandler(new MyAuthHandler());
int port = server.getLocalPort();
server.start();
URL url = new URL("ftp://localhost:" + port + "/filedoesNotExist.txt");
for (int i = 0; i < 3; i++) {
try {
InputStream stream = url.openStream();
} catch (FileNotFoundException expectedFirstTimeAround) {
// should always reach this point since the path does not exist
} catch (IOException expected) {
System.out.println("caught expected " + expected);
int times = 1;
do {
// give some time to close the connection...
System.out.println("sleeping... " + times);
Thread.sleep(times * 1000);
} while (server.activeClientsCount() > 0 && times++ < 5);
if (server.activeClientsCount() > 0) {
server.killClients();
throw new RuntimeException("URLConnection didn't close the" +
" FTP connection on FileNotFoundException");
}
} finally {
server.terminate();
}
}
}
static class CustomFileSystemHandler implements FtpFileSystemHandler {
private String currentDir;
public CustomFileSystemHandler(String path) {
currentDir = path;
}
@Override
public boolean cd(String path) {
currentDir = path;
return true;
}
@Override
public boolean cdUp() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String pwd() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean fileExists(String name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public InputStream getFile(String name) {
return null; //return null so that server will return 550 File not found.
}
@Override
public long getFileSize(String name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public InputStream listCurrentDir() {
return null;
}
@Override
public OutputStream putFile(String name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean removeFile(String name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean mkdir(String name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean rename(String from, String to) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
static class MyAuthHandler implements FtpAuthHandler {
@Override
public int authType() {
return 0;
}
@Override
public boolean authenticate(String user, String password) {
return true;
}
@Override
public boolean authenticate(String user, String password, String account) {
return true;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册