diff --git a/.hgtags b/.hgtags index 485acf67394a2267864f0a29af1e8d1478a0abc0..2be74cbcfbb60d3cfe9533567d9e04d74481c02d 100644 --- a/.hgtags +++ b/.hgtags @@ -689,4 +689,8 @@ a01d217a232906e82f80e5bc3db4d60c4c74716e jdk8u131-b02 0f7d02f565658a89b073ee77c296f33148c50da3 jdk8u131-b04 af0e709d28f9124dd2c37069e0bf4c0751248c61 jdk8u131-b05 3c7f99282d1b5e29f7466bf25fb6878bfebfc58a jdk8u131-b06 +f5d0aadb4d1ca74eda4e98cc0030f1618ef4c870 jdk8u131-b07 +6e362e6002abc39c63fc8ab4bcebf08e273f5a94 jdk8u131-b08 +40d00399869d8a28cfecf360234f340e9e0ad3b1 jdk8u131-b09 +c0091a673d766ce2e76a945bab6de325fe78dd88 jdk8u131-b10 a160009bbe1417d85f1c0eec890fdb17391b3637 jdk8u141-b00 diff --git a/src/share/classes/java/io/ObjectInputStream.java b/src/share/classes/java/io/ObjectInputStream.java index b5cb8288deae8793eeac3b62973490a71c085424..bb75d03b1fd25ec156e2ae8f650b3fbd22f07418 100644 --- a/src/share/classes/java/io/ObjectInputStream.java +++ b/src/share/classes/java/io/ObjectInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -1774,12 +1774,19 @@ public class ObjectInputStream } catch (ClassNotFoundException ex) { resolveEx = ex; } - skipCustomData(); - desc.initProxy(cl, resolveEx, readClassDesc(false)); + // Call filterCheck on the class before reading anything else + filterCheck(cl, -1); + + skipCustomData(); - // Call filterCheck on the definition - filterCheck(desc.forClass(), -1); + try { + totalObjectRefs++; + depth++; + desc.initProxy(cl, resolveEx, readClassDesc(false)); + } finally { + depth--; + } handles.finish(descHandle); passHandle = descHandle; @@ -1824,12 +1831,19 @@ public class ObjectInputStream } catch (ClassNotFoundException ex) { resolveEx = ex; } - skipCustomData(); - desc.initNonProxy(readDesc, cl, resolveEx, readClassDesc(false)); + // Call filterCheck on the class before reading anything else + filterCheck(cl, -1); + + skipCustomData(); - // Call filterCheck on the definition - filterCheck(desc.forClass(), -1); + try { + totalObjectRefs++; + depth++; + desc.initNonProxy(readDesc, cl, resolveEx, readClassDesc(false)); + } finally { + depth--; + } handles.finish(descHandle); passHandle = descHandle; diff --git a/src/share/classes/java/lang/Thread.java b/src/share/classes/java/lang/Thread.java index 7c8e83ef2b92681121cc35c63b6453d2c504645d..0cd6778684db3016e3b84e4c7aeebc77aeb59097 100644 --- a/src/share/classes/java/lang/Thread.java +++ b/src/share/classes/java/lang/Thread.java @@ -342,11 +342,11 @@ class Thread implements Runnable { /** * Initializes a Thread with the current AccessControlContext. - * @see #init(ThreadGroup,Runnable,String,long,AccessControlContext) + * @see #init(ThreadGroup,Runnable,String,long,AccessControlContext,boolean) */ private void init(ThreadGroup g, Runnable target, String name, long stackSize) { - init(g, target, name, stackSize, null); + init(g, target, name, stackSize, null, true); } /** @@ -359,9 +359,12 @@ class Thread implements Runnable { * zero to indicate that this parameter is to be ignored. * @param acc the AccessControlContext to inherit, or * AccessController.getContext() if null + * @param inheritThreadLocals if {@code true}, inherit initial values for + * inheritable thread-locals from the constructing thread */ private void init(ThreadGroup g, Runnable target, String name, - long stackSize, AccessControlContext acc) { + long stackSize, AccessControlContext acc, + boolean inheritThreadLocals) { if (name == null) { throw new NullPointerException("name cannot be null"); } @@ -412,7 +415,7 @@ class Thread implements Runnable { acc != null ? acc : AccessController.getContext(); this.target = target; setPriority(priority); - if (parent.inheritableThreadLocals != null) + if (inheritThreadLocals && parent.inheritableThreadLocals != null) this.inheritableThreadLocals = ThreadLocal.createInheritedMap(parent.inheritableThreadLocals); /* Stash the specified stack size in case the VM cares */ @@ -466,7 +469,7 @@ class Thread implements Runnable { * This is not a public constructor. */ Thread(Runnable target, AccessControlContext acc) { - init(null, target, "Thread-" + nextThreadNum(), 0, acc); + init(null, target, "Thread-" + nextThreadNum(), 0, acc, false); } /** diff --git a/src/share/classes/sun/net/ftp/impl/FtpClient.java b/src/share/classes/sun/net/ftp/impl/FtpClient.java index 0f4bf3fdfcf0c9c76d9c46826bec95c7d74b9933..36273c4380514a48b74ca5cc7cdcc85b551d7473 100644 --- a/src/share/classes/sun/net/ftp/impl/FtpClient.java +++ b/src/share/classes/sun/net/ftp/impl/FtpClient.java @@ -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 @@ public class FtpClient extends sun.net.ftp.FtpClient { * @return true 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); diff --git a/src/share/classes/sun/net/smtp/SmtpClient.java b/src/share/classes/sun/net/smtp/SmtpClient.java index fda15ea92347043503971bdcd32d067491c49c51..e96896bc5a5bf6499c0f0bd50c0541ae050b3eb5 100644 --- a/src/share/classes/sun/net/smtp/SmtpClient.java +++ b/src/share/classes/sun/net/smtp/SmtpClient.java @@ -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 @@ 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 host. */ 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); } diff --git a/src/share/classes/sun/net/www/http/HttpClient.java b/src/share/classes/sun/net/www/http/HttpClient.java index d0f2e9387181415ecf2b0317bb01b1442876d242..82f3686e1559387953eea51098b4aeb41f2a6d8a 100644 --- a/src/share/classes/sun/net/www/http/HttpClient.java +++ b/src/share/classes/sun/net/www/http/HttpClient.java @@ -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); diff --git a/src/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java b/src/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java index d787ab3df1a435dc6e004f7765eb4b8c7dca5a2d..e560abf9c287b7db69251ac6caf186a15ac075f3 100644 --- a/src/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java +++ b/src/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java @@ -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 @@ 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); diff --git a/src/share/classes/sun/security/ssl/SupportedEllipticCurvesExtension.java b/src/share/classes/sun/security/ssl/SupportedEllipticCurvesExtension.java index b7757d6a3d1e5316c3f66a22aded697afd6eb503..59f4b74d765b606b3c4b16bd750a18d78b92c109 100644 --- a/src/share/classes/sun/security/ssl/SupportedEllipticCurvesExtension.java +++ b/src/share/classes/sun/security/ssl/SupportedEllipticCurvesExtension.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 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,9 @@ import sun.security.action.GetPropertyAction; final class SupportedEllipticCurvesExtension extends HelloExtension { + /* Class and subclass dynamic debugging support */ + private static final Debug debug = Debug.getInstance("ssl"); + private static final int ARBITRARY_PRIME = 0xff01; private static final int ARBITRARY_CHAR2 = 0xff02; @@ -159,6 +162,11 @@ final class SupportedEllipticCurvesExtension extends HelloExtension { } // ignore unknown curves } } + if (idList.isEmpty() && JsseJce.isEcAvailable()) { + throw new IllegalArgumentException( + "System property jdk.tls.namedGroups(" + property + ") " + + "contains no supported elliptic curves"); + } } else { // default curves int[] ids; if (requireFips) { @@ -183,18 +191,19 @@ final class SupportedEllipticCurvesExtension extends HelloExtension { } } - if (idList.isEmpty()) { - throw new IllegalArgumentException( - "System property jdk.tls.namedGroups(" + property + ") " + - "contains no supported elliptic curves"); - } else { + if (debug != null && idList.isEmpty()) { + debug.println( + "Initialized [jdk.tls.namedGroups|default] list contains " + + "no available elliptic curves. " + + (property != null ? "(" + property + ")" : "[Default]")); + } + supportedCurveIds = new int[idList.size()]; int i = 0; for (Integer id : idList) { supportedCurveIds[i++] = id; } } - } // check whether the curve is supported by the underlying providers private static boolean isAvailableCurve(int curveId) { diff --git a/src/share/classes/sun/security/util/AbstractAlgorithmConstraints.java b/src/share/classes/sun/security/util/AbstractAlgorithmConstraints.java index e7ed756331ce3bf7fd2dfe98583b09b40c508c46..2f7bc0c16afa402e339336f8bcdf4290e85bc4bf 100644 --- a/src/share/classes/sun/security/util/AbstractAlgorithmConstraints.java +++ b/src/share/classes/sun/security/util/AbstractAlgorithmConstraints.java @@ -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 diff --git a/src/windows/native/java/lang/java_props_md.c b/src/windows/native/java/lang/java_props_md.c index 8bf371854d4a6293826af5d8f874ec026ab54b90..e3387b677f3159d7334ef754222c412ef08b489d 100644 --- a/src/windows/native/java/lang/java_props_md.c +++ b/src/windows/native/java/lang/java_props_md.c @@ -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 @@ 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)"; } } diff --git a/test/java/io/Serializable/serialFilter/SerialFilterTest.java b/test/java/io/Serializable/serialFilter/SerialFilterTest.java index 0ab3246a6f42f68aa27d6a1d5ef869d773104006..479b849217ea70bba1bde61a4cc58cd2c2edf1e2 100644 --- a/test/java/io/Serializable/serialFilter/SerialFilterTest.java +++ b/test/java/io/Serializable/serialFilter/SerialFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 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 @@ -33,10 +33,11 @@ import java.lang.invoke.SerializedLambda; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Proxy; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Hashtable; -import java.util.Set; +import java.util.List; import java.util.concurrent.atomic.LongAdder; import sun.misc.ObjectInputFilter; @@ -155,26 +156,33 @@ public class SerialFilterTest implements Serializable { Runnable runnable = (Runnable & Serializable) SerialFilterTest::noop; Object[][] objects = { { null, 0, -1, 0, 0, 0, - new HashSet<>()}, // no callback, no values - { objArray, 3, 7, 8, 2, 55, - new HashSet<>(Arrays.asList(objArray.getClass()))}, - { Object[].class, 1, -1, 1, 1, 40, - new HashSet<>(Arrays.asList(Object[].class))}, - { new SerialFilterTest(), 1, -1, 1, 1, 37, - new HashSet<>(Arrays.asList(SerialFilterTest.class))}, - { new LongAdder(), 2, -1, 1, 1, 93, - new HashSet<>(Arrays.asList(LongAdder.class, serClass))}, - { new byte[14], 2, 14, 1, 1, 27, - new HashSet<>(Arrays.asList(byteArray.getClass()))}, - { runnable, 13, 0, 10, 2, 514, - new HashSet<>(Arrays.asList(java.lang.invoke.SerializedLambda.class, + Arrays.asList()}, // no callback, no values + { objArray, 3, 7, 9, 2, 55, + Arrays.asList(objArray.getClass(), objArray.getClass())}, + { Object[].class, 1, -1, 1, 1, 38, + Arrays.asList(Object[].class)}, + { new SerialFilterTest(), 1, -1, 1, 1, 35, + Arrays.asList(SerialFilterTest.class)}, + { new LongAdder(), 2, -1, 2, 1, 93, + Arrays.asList(serClass, LongAdder.class)}, + { new byte[14], 2, 14, 2, 1, 27, + Arrays.asList(byteArray.getClass(), byteArray.getClass())}, + { runnable, 13, 0, 13, 2, 514, + Arrays.asList(java.lang.invoke.SerializedLambda.class, + objArray.getClass(), + objArray.getClass(), SerialFilterTest.class, - objArray.getClass()))}, - { deepHashSet(10), 48, -1, 49, 11, 619, - new HashSet<>(Arrays.asList(HashSet.class))}, - { proxy.getClass(), 3, -1, 1, 1, 114, - new HashSet<>(Arrays.asList(Runnable.class, - java.lang.reflect.Proxy.class))}, + java.lang.invoke.SerializedLambda.class)}, + { deepHashSet(10), 48, -1, 50, 11, 619, + Arrays.asList(HashSet.class)}, + { proxy.getClass(), 3, -1, 2, 2, 112, + Arrays.asList(Runnable.class, + java.lang.reflect.Proxy.class, + java.lang.reflect.Proxy.class)}, + { new F(), 6, -1, 6, 6, 202, + Arrays.asList(F.class, E.class, D.class, + C.class, B.class, A.class)}, + }; return objects; } @@ -213,11 +221,12 @@ public class SerialFilterTest implements Serializable { @Test(dataProvider="Objects") public static void t1(Object object, long count, long maxArray, long maxRefs, long maxDepth, long maxBytes, - Set> classes) throws IOException { + List> classes) throws IOException { byte[] bytes = writeObjects(object); Validator validator = new Validator(); validate(bytes, validator); System.out.printf("v: %s%n", validator); + Assert.assertEquals(validator.count, count, "callback count wrong"); Assert.assertEquals(validator.classes, classes, "classes mismatch"); Assert.assertEquals(validator.maxArray, maxArray, "maxArray mismatch"); @@ -411,7 +420,7 @@ public class SerialFilterTest implements Serializable { */ static class Validator implements ObjectInputFilter { long count; // Count of calls to checkInput - HashSet> classes = new HashSet<>(); + List> classes = new ArrayList<>(); long maxArray = -1; long maxRefs; long maxDepth; @@ -422,16 +431,20 @@ public class SerialFilterTest implements Serializable { @Override public ObjectInputFilter.Status checkInput(FilterInfo filter) { + Class serialClass = filter.serialClass(); + System.out.printf(" checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n", + serialClass, filter.arrayLength(), filter.references(), + filter.depth(), filter.streamBytes()); count++; - if (filter.serialClass() != null) { - if (filter.serialClass().getName().contains("$$Lambda$")) { + if (serialClass != null) { + if (serialClass.getName().contains("$$Lambda$")) { // TBD: proper identification of serialized Lambdas? // Fold the serialized Lambda into the SerializedLambda type classes.add(SerializedLambda.class); - } else if (Proxy.isProxyClass(filter.serialClass())) { + } else if (Proxy.isProxyClass(serialClass)) { classes.add(Proxy.class); } else { - classes.add(filter.serialClass()); + classes.add(serialClass); } } @@ -591,7 +604,8 @@ public class SerialFilterTest implements Serializable { // a stream of exactly the size requested. return genMaxBytesObject(allowed, value); } else if (pattern.startsWith("maxrefs=")) { - Object[] array = new Object[allowed ? (int)value - 1 : (int)value]; + // 4 references to classes in addition to the array contents + Object[] array = new Object[allowed ? (int)value - 4 : (int)value - 3]; for (int i = 0; i < array.length; i++) { array[i] = otherObject; } @@ -740,4 +754,25 @@ public class SerialFilterTest implements Serializable { return streamBytes; } } + + // Deeper superclass hierarchy + static class A implements Serializable { + private static final long serialVersionUID = 1L; + }; + static class B extends A { + private static final long serialVersionUID = 2L; + } + static class C extends B { + private static final long serialVersionUID = 3L; + } + static class D extends C { + private static final long serialVersionUID = 4L; + } + static class E extends D { + private static final long serialVersionUID = 5L; + } + static class F extends E { + private static final long serialVersionUID = 6L; + } + } diff --git a/test/java/lang/Thread/ITLConstructor.java b/test/java/lang/Thread/ITLConstructor.java new file mode 100644 index 0000000000000000000000000000000000000000..1a24f0a15168d34fa7ee492ccd2e9d63fd3577e5 --- /dev/null +++ b/test/java/lang/Thread/ITLConstructor.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015, 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 + * @summary Basic test for Thread(ThreadGroup,Runnable,String,long,boolean) + */ + +import sun.misc.SharedSecrets; + +import java.security.AccessControlContext; +import java.security.AccessController; +import java.security.PrivilegedAction; + +public class ITLConstructor { + static InheritableThreadLocal n = new InheritableThreadLocal() { + protected Integer initialValue() { + return 0; + } + + protected Integer childValue(Integer parentValue) { + return parentValue + 1; + } + }; + + static final int CHILD_THREAD_COUNT = 10; + + public static void main(String args[]) throws Exception { + test(); + } + + static void test() throws Exception { + // concurrent access to separate indexes is ok + int[] x = new int[CHILD_THREAD_COUNT]; + Thread child = createThread(new AnotherRunnable(0, x)); + child.start(); + child.join(); // waits for *all* threads to complete + + // Check results + for(int i=0; i() { + public Thread run() { + return SharedSecrets.getJavaLangAccess() + .newThreadWithAcc(r, acc); + } + } + ); + } +} diff --git a/test/sun/net/ftp/FtpURLConnectionLeak.java b/test/sun/net/ftp/FtpURLConnectionLeak.java new file mode 100644 index 0000000000000000000000000000000000000000..eea7a61e5ec70693326faf42dc125dd3761ecc8b --- /dev/null +++ b/test/sun/net/ftp/FtpURLConnectionLeak.java @@ -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; + } + } +} diff --git a/test/sun/security/ssl/ServerHandshaker/HelloExtensionsTest.java b/test/sun/security/ssl/ServerHandshaker/HelloExtensionsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..51c866ea1a03f9f214b73531057fe204a9a5f472 --- /dev/null +++ b/test/sun/security/ssl/ServerHandshaker/HelloExtensionsTest.java @@ -0,0 +1,287 @@ +/* + * Copyright (c) 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 + * 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 8173783 + * @summary 6u141 IllegalArgumentException: jdk.tls.namedGroups + * run main/othervm HelloExtensionsTest + * run main/othervm HelloExtensionsTest -Djdk.tls.namedGroups="bug, bug" + * run main/othervm HelloExtensionsTest -Djdk.tls.namedGroups="secp521r1" + * + */ +import javax.crypto.*; +import javax.net.ssl.*; +import javax.net.ssl.SSLEngineResult.*; +import java.io.*; +import java.nio.*; +import java.security.*; + +public class HelloExtensionsTest { + + private static boolean debug = false; + private static boolean proceed = true; + private static boolean EcAvailable = isEcAvailable(); + + static String pathToStores = "../etc"; + private static String keyStoreFile = "keystore"; + private static String trustStoreFile = "truststore"; + private static String passwd = "passphrase"; + + private static String keyFilename = + System.getProperty("test.src", "./") + "/" + pathToStores + + "/" + keyStoreFile; + private static String trustFilename = + System.getProperty("test.src", "./") + "/" + pathToStores + + "/" + trustStoreFile; + + private static void checkDone(SSLEngine ssle) throws Exception { + if (!ssle.isInboundDone()) { + throw new Exception("isInboundDone isn't done"); + } + if (!ssle.isOutboundDone()) { + throw new Exception("isOutboundDone isn't done"); + } + } + + private static void runTest(SSLEngine ssle) throws Exception { + + /* + + A client hello message captured via wireshark by selecting + a TLSv1.2 Client Hello record and clicking through to the + TLSv1.2 Record Layer line and then selecting the hex stream + via "copy -> bytes -> hex stream". + + For Record purposes, here's the ClientHello : + + *** ClientHello, TLSv1.2 + RandomCookie: GMT: 1469560450 bytes = { 108, 140, 12, 202, + 2, 213, 10, 236, 143, 223, 58, 162, 228, 155, 239, 3, 98, + 232, 89, 41, 116, 120, 13, 37, 105, 153, 97, 241 } + Session ID: {} + Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, + TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, + TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, + TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, + TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, + TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, + TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, + TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, + TLS_RSA_WITH_AES_128_CBC_SHA, + TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, + TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, + TLS_DHE_RSA_WITH_AES_128_CBC_SHA, + TLS_DHE_DSS_WITH_AES_128_CBC_SHA, + TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + TLS_RSA_WITH_AES_128_GCM_SHA256, + TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, + TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, + TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, + TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, + TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, + TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, + SSL_RSA_WITH_3DES_EDE_CBC_SHA, + TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, + TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, + SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, + SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, + TLS_EMPTY_RENEGOTIATION_INFO_SCSV] + Compression Methods: { 0 } + Extension elliptic_curves, curve names: {secp256r1, + sect163k1, sect163r2, secp192r1, secp224r1, sect233k1, sect233r1, + sect283k1, sect283r1, secp384r1, sect409k1, sect409r1, secp521r1, + sect571k1, sect571r1, secp160k1, secp160r1, secp160r2, sect163r1, + secp192k1, sect193r1, sect193r2, secp224k1, sect239k1, secp256k1} + Extension ec_point_formats, formats: [uncompressed] + Extension signature_algorithms, signature_algorithms: + SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, + SHA256withECDSA, SHA256withRSA, Unknown (hash:0x3, signature:0x3), + Unknown (hash:0x3, signature:0x1), SHA1withECDSA, + SHA1withRSA, SHA1withDSA + Extension server_name, server_name: + [host_name: bugs.openjdk.java.net] + */ + + String hello = "16030300df010000db03035898b7826c8c0cc" + + "a02d50aec8fdf3aa2e49bef0362e8592974780d25699961f" + + "100003ac023c027003cc025c02900670040c009c013002fc" + + "004c00e00330032c02bc02f009cc02dc031009e00a2c008c" + + "012000ac003c00d0016001300ff01000078000a003400320" + + "0170001000300130015000600070009000a0018000b000c0" + + "019000d000e000f001000110002001200040005001400080" + + "016000b00020100000d00180016060306010503050104030" + + "401030303010203020102020000001a00180000156275677" + + "32e6f70656e6a646b2e6a6176612e6e6574"; + + byte[] msg_clihello = hexStringToByteArray(hello); + ByteBuffer bf_clihello = ByteBuffer.wrap(msg_clihello); + + SSLSession session = ssle.getSession(); + int appBufferMax = session.getApplicationBufferSize(); + int netBufferMax = session.getPacketBufferSize(); + + ByteBuffer serverIn = ByteBuffer.allocate(appBufferMax + 50); + ByteBuffer serverOut = ByteBuffer.wrap("I'm Server".getBytes()); + ByteBuffer sTOc = ByteBuffer.allocate(netBufferMax); + + ssle.beginHandshake(); + + // unwrap the clientHello message. + SSLEngineResult result = ssle.unwrap(bf_clihello, serverIn); + System.out.println("server unwrap " + result); + runDelegatedTasks(result, ssle); + + if (!proceed) { + //expected exception occurred. Don't process anymore + return; + } + + // one more step, ensure the clientHello message is parsed. + SSLEngineResult.HandshakeStatus status = ssle.getHandshakeStatus(); + if ( status == HandshakeStatus.NEED_UNWRAP) { + result = ssle.unwrap(bf_clihello, serverIn); + System.out.println("server unwrap " + result); + runDelegatedTasks(result, ssle); + } else if ( status == HandshakeStatus.NEED_WRAP) { + result = ssle.wrap(serverOut, sTOc); + System.out.println("server wrap " + result); + runDelegatedTasks(result, ssle); + } else { + throw new Exception("unexpected handshake status " + status); + } + + // enough, stop + } + + /* + * If the result indicates that we have outstanding tasks to do, + * go ahead and run them in this thread. + */ + private static void runDelegatedTasks(SSLEngineResult result, + SSLEngine engine) throws Exception { + + if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) { + Runnable runnable; + try { + while ((runnable = engine.getDelegatedTask()) != null) { + log("\trunning delegated task..."); + runnable.run(); + } + } catch (ExceptionInInitializerError e) { + String v = System.getProperty("jdk.tls.namedGroups"); + if (!EcAvailable || v == null) { + // we weren't expecting this if no EC providers + throw new RuntimeException("Unexpected Error :" + e); + } + if (v != null && v.contains("bug")) { + // OK - we were expecting this Error + log("got expected error for bad jdk.tls.namedGroups"); + proceed = false; + return; + } else { + System.out.println("Unexpected error. " + + "jdk.tls.namedGroups value: " + v); + throw e; + } + } + HandshakeStatus hsStatus = engine.getHandshakeStatus(); + if (hsStatus == HandshakeStatus.NEED_TASK) { + throw new Exception( + "handshake shouldn't need additional tasks"); + } + log("\tnew HandshakeStatus: " + hsStatus); + } + } + + private static byte[] hexStringToByteArray(String s) { + int len = s.length(); + byte[] data = new byte[len / 2]; + for (int i = 0; i < len; i += 2) { + data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + + Character.digit(s.charAt(i+1), 16)); + } + return data; + } + + private static boolean isEcAvailable() { + try { + Signature.getInstance("SHA1withECDSA"); + Signature.getInstance("NONEwithECDSA"); + KeyAgreement.getInstance("ECDH"); + KeyFactory.getInstance("EC"); + KeyPairGenerator.getInstance("EC"); + AlgorithmParameters.getInstance("EC"); + } catch (Exception e) { + log("EC not available. Received: " + e); + return false; + } + return true; + } + + public static void main(String args[]) throws Exception { + SSLEngine ssle = createSSLEngine(keyFilename, trustFilename); + runTest(ssle); + System.out.println("Test Passed."); + } + + /* + * Create an initialized SSLContext to use for this test. + */ + static private SSLEngine createSSLEngine(String keyFile, String trustFile) + throws Exception { + + SSLEngine ssle; + + KeyStore ks = KeyStore.getInstance("JKS"); + KeyStore ts = KeyStore.getInstance("JKS"); + + char[] passphrase = "passphrase".toCharArray(); + + ks.load(new FileInputStream(keyFile), passphrase); + ts.load(new FileInputStream(trustFile), passphrase); + + KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); + kmf.init(ks, passphrase); + + TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); + tmf.init(ts); + + SSLContext sslCtx = SSLContext.getInstance("TLS"); + + sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); + + ssle = sslCtx.createSSLEngine(); + ssle.setUseClientMode(false); + + return ssle; + } + + + private static void log(String str) { + if (debug) { + System.out.println(str); + } + } +}