changeset 12642:9b894e4a9bd8

Merge
author asaha
date Thu, 09 Mar 2017 09:42:58 -0800
parents e8e0fa399a86 7da893a73fbc
children d1417232bd8c c8c9ddf4756c
files .hgtags
diffstat 8 files changed, 229 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Fri Feb 24 09:05:47 2017 -0800
+++ b/.hgtags	Thu Mar 09 09:42:58 2017 -0800
@@ -691,3 +691,5 @@
 3c7f99282d1b5e29f7466bf25fb6878bfebfc58a jdk8u131-b06
 f5d0aadb4d1ca74eda4e98cc0030f1618ef4c870 jdk8u131-b07
 6e362e6002abc39c63fc8ab4bcebf08e273f5a94 jdk8u131-b08
+40d00399869d8a28cfecf360234f340e9e0ad3b1 jdk8u131-b09
+c0091a673d766ce2e76a945bab6de325fe78dd88 jdk8u131-b10
--- a/src/share/classes/sun/net/ftp/impl/FtpClient.java	Fri Feb 24 09:05:47 2017 -0800
+++ b/src/share/classes/sun/net/ftp/impl/FtpClient.java	Thu Mar 09 09:42:58 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * 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 @@
      * @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 @@
                 // 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 void close() throws IOException {
         if (isConnected()) {
-            issueCommand("QUIT");
+            try {
+                issueCommand("QUIT");
+            } catch (FtpProtocolException e) {
+            }
             loggedIn = false;
         }
         disconnect();
@@ -1898,7 +1908,8 @@
         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);
--- a/src/share/classes/sun/net/smtp/SmtpClient.java	Fri Feb 24 09:05:47 2017 -0800
+++ b/src/share/classes/sun/net/smtp/SmtpClient.java	Thu Mar 09 09:42:58 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * 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 @@
 
 public class SmtpClient extends TransferProtocolClient {
 
+    private static int DEFAULT_SMTP_PORT = 25;
     String mailhost;
     SmtpPrintStream message;
 
@@ -74,6 +75,10 @@
     }
 
     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 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);
     }
 
--- a/src/share/classes/sun/net/www/http/HttpClient.java	Fri Feb 24 09:05:47 2017 -0800
+++ b/src/share/classes/sun/net/www/http/HttpClient.java	Thu Mar 09 09:42:58 2017 -0800
@@ -952,7 +952,11 @@
                 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);
--- a/src/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java	Fri Feb 24 09:05:47 2017 -0800
+++ b/src/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java	Thu Mar 09 09:42:58 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * 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 @@
             // 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 @@
                 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);
--- a/src/share/classes/sun/security/util/AbstractAlgorithmConstraints.java	Fri Feb 24 09:05:47 2017 -0800
+++ b/src/share/classes/sun/security/util/AbstractAlgorithmConstraints.java	Thu Mar 09 09:42:58 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * 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
--- a/src/windows/native/java/lang/java_props_md.c	Fri Feb 24 09:05:47 2017 -0800
+++ b/src/windows/native/java/lang/java_props_md.c	Thu Mar 09 09:42:58 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * 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 @@
          * 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 @@
                     }
                 } else {
                     switch (minorVersion) {
+                    case  0: sprops.os_name = "Windows Server 2016";           break;
                     default: sprops.os_name = "Windows NT (unknown)";
                     }
                 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/net/ftp/FtpURLConnectionLeak.java	Thu Mar 09 09:42:58 2017 -0800
@@ -0,0 +1,155 @@
+/*
+ * 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;
+        }
+    }
+}