OpenJDK / jdk8u / jdk8u / jdk
changeset 12037:8b04ee324a1a
Merge
author | robm |
---|---|
date | Fri, 11 Nov 2016 13:33:15 +0000 |
parents | f7be58eb30bc 15b22e564f41 |
children | e5b1823a897e efcd9a388219 1993a74c860d |
files | make/src/classes/build/tools/addtorestrictedpkgs/AddToRestrictedPkgs.java src/macosx/classes/sun/lwawt/macosx/NSPrintInfo.java |
diffstat | 68 files changed, 1399 insertions(+), 759 deletions(-) [+] |
line wrap: on
line diff
--- a/make/CopyFiles.gmk Tue Oct 25 08:40:09 2016 -0700 +++ b/make/CopyFiles.gmk Fri Nov 11 13:33:15 2016 +0000 @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 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 @@ -357,18 +357,21 @@ RESTRICTED_PKGS_SRC := $(JDK_TOPDIR)/src/closed/share/lib/security/restricted.pkgs RESTRICTED_PKGS := $(shell $(CAT) $(RESTRICTED_PKGS_SRC) | $(TR) "\n" " ") +endif + $(PROPS_DST): $(PROPS_SRC) $(MKDIR) -p $(@D) - $(TOOL_ADDTORESTRICTEDPKGS) $^ $@.tmp $(RESTRICTED_PKGS) + ifndef OPENJDK + $(TOOL_ADDTORESTRICTEDPKGS) $^ $@.tmp $(RESTRICTED_PKGS) + else + $(CP) $^ $@.tmp + endif + ifeq ($(UNLIMITED_CRYPTO), true) + $(TOOL_CRYPTOLEVEL) $@.tmp $@.tmp2 unlimited + $(MV) $@.tmp2 $@.tmp + endif $(MV) $@.tmp $@ -else - -$(PROPS_DST): $(PROPS_SRC) - $(call install-file) - -endif - COPY_FILES += $(PROPS_DST) ##########################################################################################
--- a/make/CreateSecurityJars.gmk Tue Oct 25 08:40:09 2016 -0700 +++ b/make/CreateSecurityJars.gmk Fri Nov 11 13:33:15 2016 +0000 @@ -1,5 +1,5 @@ # -# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2013, 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 @@ -178,7 +178,10 @@ ########################################################################################## -US_EXPORT_POLICY_JAR_DST := $(JDK_OUTPUTDIR)/lib/security/US_export_policy.jar +US_EXPORT_POLICY_JAR_UNLIMITED_DST := \ + $(JDK_OUTPUTDIR)/lib/security/policy/unlimited/US_export_policy.jar +US_EXPORT_POLICY_JAR_LIMITED_DST := \ + $(JDK_OUTPUTDIR)/lib/security/policy/limited/US_export_policy.jar ifneq ($(BUILD_CRYPTO), no) @@ -220,27 +223,29 @@ endif ifndef OPENJDK - ifeq ($(UNLIMITED_CRYPTO), true) - $(error No prebuilt unlimited crypto jars available) - endif - $(US_EXPORT_POLICY_JAR_DST): $(JDK_TOPDIR)/make/closed/tools/crypto/jce/US_export_policy.jar + $(US_EXPORT_POLICY_JAR_UNLIMITED_DST): \ + $(JDK_TOPDIR)/make/closed/tools/crypto/jce/unlimited/US_export_policy.jar + $(ECHO) $(LOG_INFO) Copying prebuilt $(@F) + $(install-file) + $(US_EXPORT_POLICY_JAR_LIMITED_DST): \ + $(JDK_TOPDIR)/make/closed/tools/crypto/jce/limited/US_export_policy.jar $(ECHO) $(LOG_INFO) Copying prebuilt $(@F) $(install-file) else - ifeq ($(UNLIMITED_CRYPTO), true) - $(US_EXPORT_POLICY_JAR_DST): $(US_EXPORT_POLICY_JAR_UNLIMITED_UNSIGNED) + $(US_EXPORT_POLICY_JAR_UNLIMITED_DST): $(US_EXPORT_POLICY_JAR_UNLIMITED_UNSIGNED) $(install-file) - else - $(US_EXPORT_POLICY_JAR_DST): $(US_EXPORT_POLICY_JAR_LIMITED_UNSIGNED) + $(US_EXPORT_POLICY_JAR_LIMITED_DST): $(US_EXPORT_POLICY_JAR_LIMITED_UNSIGNED) $(install-file) endif -endif -TARGETS += $(US_EXPORT_POLICY_JAR_DST) +TARGETS += $(US_EXPORT_POLICY_JAR_UNLIMITED_DST) $(US_EXPORT_POLICY_JAR_LIMITED_DST) ########################################################################################## -LOCAL_POLICY_JAR_DST := $(JDK_OUTPUTDIR)/lib/security/local_policy.jar +LOCAL_POLICY_JAR_LIMITED_DST := \ + $(JDK_OUTPUTDIR)/lib/security/policy/limited/local_policy.jar +LOCAL_POLICY_JAR_UNLIMITED_DST := \ + $(JDK_OUTPUTDIR)/lib/security/policy/unlimited/local_policy.jar ifneq ($(BUILD_CRYPTO), no) @@ -293,20 +298,20 @@ endif ifndef OPENJDK - $(LOCAL_POLICY_JAR_DST): $(JDK_TOPDIR)/make/closed/tools/crypto/jce/local_policy.jar + $(LOCAL_POLICY_JAR_UNLIMITED_DST): $(JDK_TOPDIR)/make/closed/tools/crypto/jce/unlimited/local_policy.jar + $(ECHO) $(LOG_INFO) Copying prebuilt $(@F) + $(install-file) + $(LOCAL_POLICY_JAR_LIMITED_DST): $(JDK_TOPDIR)/make/closed/tools/crypto/jce/limited/local_policy.jar $(ECHO) $(LOG_INFO) Copying prebuilt $(@F) $(install-file) else - ifeq ($(UNLIMITED_CRYPTO), true) - $(LOCAL_POLICY_JAR_DST): $(LOCAL_POLICY_JAR_UNLIMITED_UNSIGNED) + $(LOCAL_POLICY_JAR_UNLIMITED_DST): $(LOCAL_POLICY_JAR_UNLIMITED_UNSIGNED) $(install-file) - else - $(LOCAL_POLICY_JAR_DST): $(LOCAL_POLICY_JAR_LIMITED_UNSIGNED) + $(LOCAL_POLICY_JAR_LIMITED_DST): $(LOCAL_POLICY_JAR_LIMITED_UNSIGNED) $(install-file) endif -endif -TARGETS += $(LOCAL_POLICY_JAR_DST) +TARGETS += $(LOCAL_POLICY_JAR_UNLIMITED_DST) $(LOCAL_POLICY_JAR_LIMITED_DST) ##########################################################################################
--- a/make/Tools.gmk Tue Oct 25 08:40:09 2016 -0700 +++ b/make/Tools.gmk Fri Nov 11 13:33:15 2016 +0000 @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 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 @@ -132,7 +132,10 @@ build.tools.deps.CheckDeps TOOL_ADDTORESTRICTEDPKGS=$(JAVA_SMALL) -cp $(JDK_OUTPUTDIR)/btclasses \ - build.tools.addtorestrictedpkgs.AddToRestrictedPkgs + build.tools.customizesecurityfile.AddToRestrictedPkgs + +TOOL_CRYPTOLEVEL=$(JAVA_SMALL) -cp $(JDK_OUTPUTDIR)/btclasses \ + build.tools.customizesecurityfile.CryptoLevel ##########################################################################################
--- a/make/mapfiles/libnet/mapfile-vers Tue Oct 25 08:40:09 2016 -0700 +++ b/make/mapfiles/libnet/mapfile-vers Fri Nov 11 13:33:15 2016 +0000 @@ -112,6 +112,7 @@ NET_EnableFastTcpLoopback; NET_ThrowNew; ipv6_available; + initInetAddressIDs; local: *;
--- a/make/profile-includes.txt Tue Oct 25 08:40:09 2016 -0700 +++ b/make/profile-includes.txt Fri Nov 11 13:33:15 2016 +0000 @@ -1,5 +1,5 @@ # -# Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2012, 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 @@ -183,13 +183,15 @@ net.properties \ resources.jar \ rt.jar \ - security/US_export_policy.jar \ + security/policy/limited/US_export_policy.jar \ + security/policy/unlimited/US_export_policy.jar \ security/blacklist \ security/blacklisted.certs \ security/cacerts \ security/java.policy \ security/java.security \ - security/local_policy.jar \ + security/policy/limited/local_policy.jar \ + security/policy/unlimited/local_policy.jar \ security/trusted.libraries \ tzdb.dat @@ -218,8 +220,10 @@ jsse.jar \ resources.jar \ rt.jar \ - security/US_export_policy.jar \ - security/local_policy.jar + security/policy/limited/US_export_policy.jar \ + security/policy/unlimited/US_export_policy.jar \ + security/policy/limited/local_policy.jar \ + security/policy/unlimited/local_policy.jar PROFILE_2_JRE_BIN_FILES := \
--- a/make/src/classes/build/tools/addtorestrictedpkgs/AddToRestrictedPkgs.java Tue Oct 25 08:40:09 2016 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2013, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ - -package build.tools.addtorestrictedpkgs; - -import java.io.*; - -/** - * Adds additional packages to the package.access and package.definition - * security properties. - */ -public class AddToRestrictedPkgs { - - private static final String PKG_ACC = "package.access"; - private static final String PKG_DEF = "package.definition"; - private static final int PKG_ACC_INDENT = 15; - private static final int PKG_DEF_INDENT = 19; - - public static void main(String[] args) throws Exception { - - if (args.length < 3) { - System.err.println("Usage: java AddToRestrictedPkgs " + - "[input java.security file name] " + - "[output java.security file name] " + - "[packages ...]"); - System.exit(1); - } - - try (FileReader fr = new FileReader(args[0]); - BufferedReader br = new BufferedReader(fr); - FileWriter fw = new FileWriter(args[1]); - BufferedWriter bw = new BufferedWriter(fw)) - { - // parse the file line-by-line, looking for pkg access properties - String line = br.readLine(); - while (line != null) { - if (line.startsWith(PKG_ACC)) { - writePackages(br, bw, line, PKG_ACC_INDENT, args); - } else if (line.startsWith(PKG_DEF)) { - writePackages(br, bw, line, PKG_DEF_INDENT, args); - } else { - writeLine(bw, line); - } - line = br.readLine(); - } - bw.flush(); - } - } - - private static void writePackages(BufferedReader br, BufferedWriter bw, - String line, int numSpaces, - String[] args) throws IOException { - // parse property until EOL, not including line breaks - while (line.endsWith("\\")) { - writeLine(bw, line); - line = br.readLine(); - } - // append comma and line-break to last package - writeLine(bw, line + ",\\"); - // add new packages, one per line - for (int i = 2; i < args.length - 1; i++) { - indent(bw, numSpaces); - writeLine(bw, args[i] + ",\\"); - } - indent(bw, numSpaces); - writeLine(bw, args[args.length - 1]); - } - - private static void writeLine(BufferedWriter bw, String line) - throws IOException - { - bw.write(line); - bw.newLine(); - } - - private static void indent(BufferedWriter bw, int numSpaces) - throws IOException - { - for (int i = 0; i < numSpaces; i++) { - bw.append(' '); - } - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/src/classes/build/tools/customizesecurityfile/AddToRestrictedPkgs.java Fri Nov 11 13:33:15 2016 +0000 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2013, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package build.tools.customizesecurityfile; + +import java.io.*; + +/** + * Adds additional packages to the package.access and package.definition + * security properties. + */ +public class AddToRestrictedPkgs { + + private static final String PKG_ACC = "package.access"; + private static final String PKG_DEF = "package.definition"; + private static final int PKG_ACC_INDENT = 15; + private static final int PKG_DEF_INDENT = 19; + + public static void main(String[] args) throws Exception { + + if (args.length < 3) { + System.err.println("Usage: java AddToRestrictedPkgs " + + "[input java.security file name] " + + "[output java.security file name] " + + "[packages ...]"); + System.exit(1); + } + + try (FileReader fr = new FileReader(args[0]); + BufferedReader br = new BufferedReader(fr); + FileWriter fw = new FileWriter(args[1]); + BufferedWriter bw = new BufferedWriter(fw)) + { + // parse the file line-by-line, looking for pkg access properties + String line = br.readLine(); + while (line != null) { + if (line.startsWith(PKG_ACC)) { + writePackages(br, bw, line, PKG_ACC_INDENT, args); + } else if (line.startsWith(PKG_DEF)) { + writePackages(br, bw, line, PKG_DEF_INDENT, args); + } else { + writeLine(bw, line); + } + line = br.readLine(); + } + bw.flush(); + } + } + + private static void writePackages(BufferedReader br, BufferedWriter bw, + String line, int numSpaces, + String[] args) throws IOException { + // parse property until EOL, not including line breaks + while (line.endsWith("\\")) { + writeLine(bw, line); + line = br.readLine(); + } + // append comma and line-break to last package + writeLine(bw, line + ",\\"); + // add new packages, one per line + for (int i = 2; i < args.length - 1; i++) { + indent(bw, numSpaces); + writeLine(bw, args[i] + ",\\"); + } + indent(bw, numSpaces); + writeLine(bw, args[args.length - 1]); + } + + private static void writeLine(BufferedWriter bw, String line) + throws IOException + { + bw.write(line); + bw.newLine(); + } + + private static void indent(BufferedWriter bw, int numSpaces) + throws IOException + { + for (int i = 0; i < numSpaces; i++) { + bw.append(' '); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/src/classes/build/tools/customizesecurityfile/CryptoLevel.java Fri Nov 11 13:33:15 2016 +0000 @@ -0,0 +1,85 @@ +/* + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package build.tools.customizesecurityfile; + +import java.io.*; + +/** + * Alters the crypto.policy security property + * if --enable-unlimited-crypto is enabled. + */ +public class CryptoLevel { + + private static final String PROP_NAME = "crypto.policy"; + + public static void main(String[] args) throws Exception { + boolean fileModified = false; + + if (args.length < 3) { + System.err.println("Usage: java CryptoLevel" + + "[input java.security file name] " + + "[output java.security file name] " + + "[unlimited|limited]"); + System.exit(1); + } + if (!args[2].equals("unlimited") && !args[2].equals("limited")) { + System.err.println("CryptoLevel error: Unexpected " + + "input: " + args[2]); + System.exit(1); + } + + try (FileReader fr = new FileReader(args[0]); + BufferedReader br = new BufferedReader(fr); + FileWriter fw = new FileWriter(args[1]); + BufferedWriter bw = new BufferedWriter(fw)) + { + // parse the file line-by-line, looking for crypto.policy + String line = br.readLine(); + while (line != null) { + if (line.startsWith('#' + PROP_NAME) || + line.startsWith(PROP_NAME)) { + writeLine(bw, PROP_NAME + "=" + args[2]); + fileModified = true; + } else { + writeLine(bw, line); + } + line = br.readLine(); + } + if (!fileModified) { + //no previous setting seen. Insert at end + writeLine(bw, PROP_NAME + "=" + args[2]); + } + bw.flush(); + } + } + + private static void writeLine(BufferedWriter bw, String line) + throws IOException + { + bw.write(line); + bw.newLine(); + } +}
--- a/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java Tue Oct 25 08:40:09 2016 -0700 +++ b/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java Fri Nov 11 13:33:15 2016 +0000 @@ -177,12 +177,6 @@ return; } - // See if this has an NSPrintInfo in it. - NSPrintInfo nsPrintInfo = (NSPrintInfo)attributes.get(NSPrintInfo.class); - if (nsPrintInfo != null) { - fNSPrintInfo = nsPrintInfo.getValue(); - } - PageRanges pageRangesAttr = (PageRanges)attributes.get(PageRanges.class); if (isSupportedValue(pageRangesAttr, attributes)) { SunPageSelection rangeSelect = (SunPageSelection)attributes.get(SunPageSelection.class); @@ -535,8 +529,11 @@ @Override protected void finalize() { - if (fNSPrintInfo != -1) { - dispose(fNSPrintInfo); + synchronized (fNSPrintInfoLock) { + if (fNSPrintInfo != -1) { + dispose(fNSPrintInfo); + } + fNSPrintInfo = -1; } }
--- a/src/macosx/classes/sun/lwawt/macosx/NSPrintInfo.java Tue Oct 25 08:40:09 2016 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2011, 2012, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ - -package sun.lwawt.macosx; - - -import java.io.*; -import javax.print.attribute.*; - -public final class NSPrintInfo implements PrintJobAttribute, PrintRequestAttribute, Serializable, Cloneable { - - private long fNSPrintInfo; - - public NSPrintInfo(long nsPrintInfo) { - fNSPrintInfo = nsPrintInfo; - } - - public long getValue() { - return fNSPrintInfo; - } - - public boolean equals(Object object) { - return (object != null && object instanceof NSPrintInfo && fNSPrintInfo == ((NSPrintInfo)object).fNSPrintInfo); - } - - public int hashCode() { - return (int)fNSPrintInfo; - } - - public String toString() { - return "" + fNSPrintInfo; - } - - public final Class<? extends Attribute> getCategory() { - return NSPrintInfo.class; - } - - public final String getName() { - return "nsPrintInfo"; - } -}
--- a/src/macosx/native/sun/osxapp/NSApplicationAWT.m Tue Oct 25 08:40:09 2016 -0700 +++ b/src/macosx/native/sun/osxapp/NSApplicationAWT.m Fri Nov 11 13:33:15 2016 +0000 @@ -363,7 +363,6 @@ { void (^copy)() = [block copy]; NSInteger encode = (NSInteger) copy; - [copy retain]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined location: NSMakePoint(0,0)
--- a/src/share/classes/javax/crypto/JceSecurity.java Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/classes/javax/crypto/JceSecurity.java Fri Nov 11 13:33:15 2016 +0000 @@ -29,12 +29,14 @@ import java.util.jar.*; import java.io.*; import java.net.URL; +import java.nio.file.*; import java.security.*; import java.security.Provider.Service; import sun.security.jca.*; import sun.security.jca.GetInstance.Instance; +import sun.security.util.Debug; /** * This class instantiates implementations of JCE engine classes from @@ -66,6 +68,9 @@ private static final boolean isRestricted; + private static final Debug debug = + Debug.getInstance("jca", "Cipher"); + /* * Don't let anyone instantiate this. */ @@ -204,7 +209,7 @@ static { try { - NULL_URL = new URL("http://null.sun.com/"); + NULL_URL = new URL("http://null.oracle.com/"); } catch (Exception e) { throw new RuntimeException(e); } @@ -239,14 +244,70 @@ } } + /* + * This is called from within an doPrivileged block. + * + * Following logic is used to decide what policy files are selected. + * + * If the new Security property (crypto.policy) is set in the + * java.security file, or has been set dynamically using the + * Security.setProperty() call before the JCE framework has + * been initialized, that setting will be used. + * Remember - this property is not defined by default. A conscious + * user edit or an application call is required. + * + * Otherwise, if user has policy jar files installed in the legacy + * jre/lib/security/ directory, the JDK will honor whatever + * setting is set by those policy files. (legacy/current behavior) + * + * If none of the above 2 conditions are met, the JDK will default + * to using the limited crypto policy files found in the + * jre/lib/security/policy/limited/ directory + */ private static void setupJurisdictionPolicies() throws Exception { - String javaHomeDir = System.getProperty("java.home"); - String sep = File.separator; - String pathToPolicyJar = javaHomeDir + sep + "lib" + sep + - "security" + sep; + // Sanity check the crypto.policy Security property. Single + // directory entry, no pseudo-directories (".", "..", leading/trailing + // path separators). normalize()/getParent() will help later. + String javaHomeProperty = System.getProperty("java.home"); + String cryptoPolicyProperty = Security.getProperty("crypto.policy"); + Path cpPath = (cryptoPolicyProperty == null) ? null : + Paths.get(cryptoPolicyProperty); - File exportJar = new File(pathToPolicyJar, "US_export_policy.jar"); - File importJar = new File(pathToPolicyJar, "local_policy.jar"); + if ((cpPath != null) && ((cpPath.getNameCount() != 1) || + (cpPath.compareTo(cpPath.getFileName())) != 0)) { + throw new SecurityException( + "Invalid policy directory name format: " + + cryptoPolicyProperty); + } + + if (cpPath == null) { + // Security property is not set, use default path + cpPath = Paths.get(javaHomeProperty, "lib", "security"); + } else { + // populate with java.home + cpPath = Paths.get(javaHomeProperty, "lib", "security", + "policy", cryptoPolicyProperty); + } + + if (debug != null) { + debug.println("crypto policy directory: " + cpPath); + } + + File exportJar = new File(cpPath.toFile(),"US_export_policy.jar"); + File importJar = new File(cpPath.toFile(),"local_policy.jar"); + + if (cryptoPolicyProperty == null && (!exportJar.exists() || + !importJar.exists())) { + // Compatibility set up. If crypto.policy is not defined. + // check to see if legacy jars exist in lib directory. If + // they don't exist, we default to limited policy mode. + cpPath = Paths.get( + javaHomeProperty, "lib", "security", "policy", "limited"); + // point to the new jar files in limited directory + exportJar = new File(cpPath.toFile(),"US_export_policy.jar"); + importJar = new File(cpPath.toFile(),"local_policy.jar"); + } + URL jceCipherURL = ClassLoader.getSystemResource ("javax/crypto/Cipher.class");
--- a/src/share/classes/sun/security/krb5/PrincipalName.java Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/classes/sun/security/krb5/PrincipalName.java Fri Nov 11 13:33:15 2016 +0000 @@ -424,6 +424,9 @@ } catch (UnknownHostException | SecurityException e) { // not canonicalized or no permission to do so, use old } + if (hostName.endsWith(".")) { + hostName = hostName.substring(0, hostName.length() - 1); + } nameParts[1] = hostName.toLowerCase(Locale.ENGLISH); } nameStrings = nameParts;
--- a/src/share/classes/sun/security/ssl/RSAClientKeyExchange.java Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/classes/sun/security/ssl/RSAClientKeyExchange.java Fri Nov 11 13:33:15 2016 +0000 @@ -255,7 +255,13 @@ @Override void print(PrintStream s) throws IOException { - s.println("*** ClientKeyExchange, RSA PreMasterSecret, " + - protocolVersion); + String version = "version not available/extractable"; + + byte[] ba = preMaster.getEncoded(); + if (ba != null && ba.length >= 2) { + version = ProtocolVersion.valueOf(ba[0], ba[1]).name; + } + + s.println("*** ClientKeyExchange, RSA PreMasterSecret, " + version); } }
--- a/src/share/lib/security/java.security-aix Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/lib/security/java.security-aix Fri Nov 11 13:33:15 2016 +0000 @@ -661,3 +661,68 @@ # E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED \ # EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381 \ # FFFFFFFF FFFFFFFF, 2} + +# Cryptographic Jurisdiction Policy defaults +# +# Due to the import control restrictions of some countries, the default +# JCE policy files allow for strong but "limited" cryptographic key +# lengths to be used. If your country's cryptographic regulations allow, +# the "unlimited" strength policy files can be used instead, which contain +# no restrictions on cryptographic strengths. +# +# YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY +# TO DETERMINE THE EXACT REQUIREMENTS. +# +# <java-home> (below) refers to the directory where the JRE was +# installed. It is determined based on whether you are running JCE +# on a JRE or a JRE contained within the Java Development Kit, or +# JDK(TM). The JDK contains the JRE, but at a different level in the +# file hierarchy. For example, if the JDK is installed in +# /home/user1/jdk1.8.0 on Unix or in C:\jdk1.8.0 on Windows, then +# <java-home> is: +# +# /home/user1/jdk1.8.0/jre [Unix] +# C:\jdk1.8.0\jre [Windows] +# +# If on the other hand the JRE is installed in /home/user1/jre1.8.0 +# on Unix or in C:\jre1.8.0 on Windows, and the JDK is not +# installed, then <java-home> is: +# +# /home/user1/jre1.8.0 [Unix] +# C:\jre1.8.0 [Windows] +# +# On Windows, for each JDK installation, there may be additional +# JREs installed under the "Program Files" directory. Please make +# sure that you install the unlimited strength policy JAR files +# for all JREs that you plan to use. +# +# The policy files are jar files organized into subdirectories of +# <java-home>/lib/security/policy. Each directory contains a complete +# set of policy files. +# +# The "crypto.policy" Security property controls the directory selection, +# and thus the effective cryptographic policy. +# +# The default set of directories is: +# +# limited | unlimited +# +# however other directories can be created and configured. +# +# To support older JDK Update releases, the crypto.policy property +# is not defined by default. When the property is not defined, an +# update release binary aware of the new property will use the following +# logic to decide what crypto policy files get used : +# +# * If the US_export_policy.jar and local_policy.jar files are located +# in the (legacy) <java-home>/lib/security directory, then the rules +# embedded in those jar files will be used. This helps preserve compatibility +# for users upgrading from an older installation. +# +# * If crypto.policy is not defined and no such jar files are present in +# the legacy locations, then the JDK will use the limited settings +# (equivalent to crypto.policy=limited) +# +# Please see the JCA documentation for additional information on these +# files and formats. +#crypto.policy=unlimited
--- a/src/share/lib/security/java.security-linux Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/lib/security/java.security-linux Fri Nov 11 13:33:15 2016 +0000 @@ -661,3 +661,68 @@ # E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED \ # EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381 \ # FFFFFFFF FFFFFFFF, 2} + +# Cryptographic Jurisdiction Policy defaults +# +# Due to the import control restrictions of some countries, the default +# JCE policy files allow for strong but "limited" cryptographic key +# lengths to be used. If your country's cryptographic regulations allow, +# the "unlimited" strength policy files can be used instead, which contain +# no restrictions on cryptographic strengths. +# +# YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY +# TO DETERMINE THE EXACT REQUIREMENTS. +# +# <java-home> (below) refers to the directory where the JRE was +# installed. It is determined based on whether you are running JCE +# on a JRE or a JRE contained within the Java Development Kit, or +# JDK(TM). The JDK contains the JRE, but at a different level in the +# file hierarchy. For example, if the JDK is installed in +# /home/user1/jdk1.8.0 on Unix or in C:\jdk1.8.0 on Windows, then +# <java-home> is: +# +# /home/user1/jdk1.8.0/jre [Unix] +# C:\jdk1.8.0\jre [Windows] +# +# If on the other hand the JRE is installed in /home/user1/jre1.8.0 +# on Unix or in C:\jre1.8.0 on Windows, and the JDK is not +# installed, then <java-home> is: +# +# /home/user1/jre1.8.0 [Unix] +# C:\jre1.8.0 [Windows] +# +# On Windows, for each JDK installation, there may be additional +# JREs installed under the "Program Files" directory. Please make +# sure that you install the unlimited strength policy JAR files +# for all JREs that you plan to use. +# +# The policy files are jar files organized into subdirectories of +# <java-home>/lib/security/policy. Each directory contains a complete +# set of policy files. +# +# The "crypto.policy" Security property controls the directory selection, +# and thus the effective cryptographic policy. +# +# The default set of directories is: +# +# limited | unlimited +# +# however other directories can be created and configured. +# +# To support older JDK Update releases, the crypto.policy property +# is not defined by default. When the property is not defined, an +# update release binary aware of the new property will use the following +# logic to decide what crypto policy files get used : +# +# * If the US_export_policy.jar and local_policy.jar files are located +# in the (legacy) <java-home>/lib/security directory, then the rules +# embedded in those jar files will be used. This helps preserve compatibility +# for users upgrading from an older installation. +# +# * If crypto.policy is not defined and no such jar files are present in +# the legacy locations, then the JDK will use the limited settings +# (equivalent to crypto.policy=limited) +# +# Please see the JCA documentation for additional information on these +# files and formats. +#crypto.policy=unlimited
--- a/src/share/lib/security/java.security-macosx Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/lib/security/java.security-macosx Fri Nov 11 13:33:15 2016 +0000 @@ -664,3 +664,68 @@ # E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED \ # EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381 \ # FFFFFFFF FFFFFFFF, 2} + +# Cryptographic Jurisdiction Policy defaults +# +# Due to the import control restrictions of some countries, the default +# JCE policy files allow for strong but "limited" cryptographic key +# lengths to be used. If your country's cryptographic regulations allow, +# the "unlimited" strength policy files can be used instead, which contain +# no restrictions on cryptographic strengths. +# +# YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY +# TO DETERMINE THE EXACT REQUIREMENTS. +# +# <java-home> (below) refers to the directory where the JRE was +# installed. It is determined based on whether you are running JCE +# on a JRE or a JRE contained within the Java Development Kit, or +# JDK(TM). The JDK contains the JRE, but at a different level in the +# file hierarchy. For example, if the JDK is installed in +# /home/user1/jdk1.8.0 on Unix or in C:\jdk1.8.0 on Windows, then +# <java-home> is: +# +# /home/user1/jdk1.8.0/jre [Unix] +# C:\jdk1.8.0\jre [Windows] +# +# If on the other hand the JRE is installed in /home/user1/jre1.8.0 +# on Unix or in C:\jre1.8.0 on Windows, and the JDK is not +# installed, then <java-home> is: +# +# /home/user1/jre1.8.0 [Unix] +# C:\jre1.8.0 [Windows] +# +# On Windows, for each JDK installation, there may be additional +# JREs installed under the "Program Files" directory. Please make +# sure that you install the unlimited strength policy JAR files +# for all JREs that you plan to use. +# +# The policy files are jar files organized into subdirectories of +# <java-home>/lib/security/policy. Each directory contains a complete +# set of policy files. +# +# The "crypto.policy" Security property controls the directory selection, +# and thus the effective cryptographic policy. +# +# The default set of directories is: +# +# limited | unlimited +# +# however other directories can be created and configured. +# +# To support older JDK Update releases, the crypto.policy property +# is not defined by default. When the property is not defined, an +# update release binary aware of the new property will use the following +# logic to decide what crypto policy files get used : +# +# * If the US_export_policy.jar and local_policy.jar files are located +# in the (legacy) <java-home>/lib/security directory, then the rules +# embedded in those jar files will be used. This helps preserve compatibility +# for users upgrading from an older installation. +# +# * If crypto.policy is not defined and no such jar files are present in +# the legacy locations, then the JDK will use the limited settings +# (equivalent to crypto.policy=limited) +# +# Please see the JCA documentation for additional information on these +# files and formats. +#crypto.policy=unlimited
--- a/src/share/lib/security/java.security-solaris Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/lib/security/java.security-solaris Fri Nov 11 13:33:15 2016 +0000 @@ -663,3 +663,68 @@ # E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED \ # EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381 \ # FFFFFFFF FFFFFFFF, 2} + +# Cryptographic Jurisdiction Policy defaults +# +# Due to the import control restrictions of some countries, the default +# JCE policy files allow for strong but "limited" cryptographic key +# lengths to be used. If your country's cryptographic regulations allow, +# the "unlimited" strength policy files can be used instead, which contain +# no restrictions on cryptographic strengths. +# +# YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY +# TO DETERMINE THE EXACT REQUIREMENTS. +# +# <java-home> (below) refers to the directory where the JRE was +# installed. It is determined based on whether you are running JCE +# on a JRE or a JRE contained within the Java Development Kit, or +# JDK(TM). The JDK contains the JRE, but at a different level in the +# file hierarchy. For example, if the JDK is installed in +# /home/user1/jdk1.8.0 on Unix or in C:\jdk1.8.0 on Windows, then +# <java-home> is: +# +# /home/user1/jdk1.8.0/jre [Unix] +# C:\jdk1.8.0\jre [Windows] +# +# If on the other hand the JRE is installed in /home/user1/jre1.8.0 +# on Unix or in C:\jre1.8.0 on Windows, and the JDK is not +# installed, then <java-home> is: +# +# /home/user1/jre1.8.0 [Unix] +# C:\jre1.8.0 [Windows] +# +# On Windows, for each JDK installation, there may be additional +# JREs installed under the "Program Files" directory. Please make +# sure that you install the unlimited strength policy JAR files +# for all JREs that you plan to use. +# +# The policy files are jar files organized into subdirectories of +# <java-home>/lib/security/policy. Each directory contains a complete +# set of policy files. +# +# The "crypto.policy" Security property controls the directory selection, +# and thus the effective cryptographic policy. +# +# The default set of directories is: +# +# limited | unlimited +# +# however other directories can be created and configured. +# +# To support older JDK Update releases, the crypto.policy property +# is not defined by default. When the property is not defined, an +# update release binary aware of the new property will use the following +# logic to decide what crypto policy files get used : +# +# * If the US_export_policy.jar and local_policy.jar files are located +# in the (legacy) <java-home>/lib/security directory, then the rules +# embedded in those jar files will be used. This helps preserve compatibility +# for users upgrading from an older installation. +# +# * If crypto.policy is not defined and no such jar files are present in +# the legacy locations, then the JDK will use the limited settings +# (equivalent to crypto.policy=limited) +# +# Please see the JCA documentation for additional information on these +# files and formats. +#crypto.policy=unlimited
--- a/src/share/lib/security/java.security-windows Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/lib/security/java.security-windows Fri Nov 11 13:33:15 2016 +0000 @@ -664,3 +664,68 @@ # E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED \ # EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381 \ # FFFFFFFF FFFFFFFF, 2} + +# Cryptographic Jurisdiction Policy defaults +# +# Due to the import control restrictions of some countries, the default +# JCE policy files allow for strong but "limited" cryptographic key +# lengths to be used. If your country's cryptographic regulations allow, +# the "unlimited" strength policy files can be used instead, which contain +# no restrictions on cryptographic strengths. +# +# YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY +# TO DETERMINE THE EXACT REQUIREMENTS. +# +# <java-home> (below) refers to the directory where the JRE was +# installed. It is determined based on whether you are running JCE +# on a JRE or a JRE contained within the Java Development Kit, or +# JDK(TM). The JDK contains the JRE, but at a different level in the +# file hierarchy. For example, if the JDK is installed in +# /home/user1/jdk1.8.0 on Unix or in C:\jdk1.8.0 on Windows, then +# <java-home> is: +# +# /home/user1/jdk1.8.0/jre [Unix] +# C:\jdk1.8.0\jre [Windows] +# +# If on the other hand the JRE is installed in /home/user1/jre1.8.0 +# on Unix or in C:\jre1.8.0 on Windows, and the JDK is not +# installed, then <java-home> is: +# +# /home/user1/jre1.8.0 [Unix] +# C:\jre1.8.0 [Windows] +# +# On Windows, for each JDK installation, there may be additional +# JREs installed under the "Program Files" directory. Please make +# sure that you install the unlimited strength policy JAR files +# for all JREs that you plan to use. +# +# The policy files are jar files organized into subdirectories of +# <java-home>/lib/security/policy. Each directory contains a complete +# set of policy files. +# +# The "crypto.policy" Security property controls the directory selection, +# and thus the effective cryptographic policy. +# +# The default set of directories is: +# +# limited | unlimited +# +# however other directories can be created and configured. +# +# To support older JDK Update releases, the crypto.policy property +# is not defined by default. When the property is not defined, an +# update release binary aware of the new property will use the following +# logic to decide what crypto policy files get used : +# +# * If the US_export_policy.jar and local_policy.jar files are located +# in the (legacy) <java-home>/lib/security directory, then the rules +# embedded in those jar files will be used. This helps preserve compatibility +# for users upgrading from an older installation. +# +# * If crypto.policy is not defined and no such jar files are present in +# the legacy locations, then the JDK will use the limited settings +# (equivalent to crypto.policy=limited) +# +# Please see the JCA documentation for additional information on these +# files and formats. +#crypto.policy=unlimited
--- a/src/share/native/com/sun/tools/jdi/SharedMemoryConnection.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/native/com/sun/tools/jdi/SharedMemoryConnection.c Fri Nov 11 13:33:15 2016 +0000 @@ -174,9 +174,20 @@ * Get the packet header */ (*env)->GetByteArrayRegion(env, b, 0, sizeof(pktHeader), pktHeader); + if ((*env)->ExceptionOccurred(env)) { + /* b shorter than sizeof(pktHeader) */ + return; + } total_length = (int)pktHeader[3] | ((int)pktHeader[2] << 8) | ((int)pktHeader[1] << 16) | ((int)pktHeader[0] << 24); + + if (total_length < sizeof(pktHeader)) { + throwException(env, "java/lang/IllegalArgumentException", + "JDWP header is incorrect"); + return; + } + /* * The id field is in big endian (also errorCode field in the case * of reply packets). @@ -195,9 +206,9 @@ } /* - * The length of the JDWP packet is 11 + data + * The length of the JDWP packet is sizeof(pktHeader) + data */ - data_length = total_length - 11; + data_length = total_length - sizeof(pktHeader); if (data_length == 0) { data = NULL; @@ -209,7 +220,7 @@ return; } - (*env)->GetByteArrayRegion(env, b, 11, /*sizeof(CmdPacket)+4*/ data_length, data); + (*env)->GetByteArrayRegion(env, b, sizeof(pktHeader), /*sizeof(CmdPacket)+4*/ data_length, data); if ((*env)->ExceptionOccurred(env)) { free(data); return;
--- a/src/share/native/java/io/io_util.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/native/java/io/io_util.c Fri Nov 11 13:33:15 2016 +0000 @@ -216,6 +216,7 @@ #else why = JNU_NewStringPlatform(env, buf); #endif + CHECK_NULL(why); } x = JNU_NewObjectByName(env, "java/io/FileNotFoundException",
--- a/src/share/native/java/lang/ClassLoader.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/native/java/lang/ClassLoader.c Fri Nov 11 13:33:15 2016 +0000 @@ -132,7 +132,6 @@ if (name != NULL) { utfName = getUTF(env, name, buf, sizeof(buf)); if (utfName == NULL) { - JNU_ThrowOutOfMemoryError(env, NULL); goto free_body; } VerifyFixClassname(utfName); @@ -143,7 +142,6 @@ if (source != NULL) { utfSource = getUTF(env, source, sourceBuf, sizeof(sourceBuf)); if (utfSource == NULL) { - JNU_ThrowOutOfMemoryError(env, NULL); goto free_utfName; } } else { @@ -517,7 +515,6 @@ procHandle = getProcessHandle(); cname = JNU_GetStringPlatformChars(env, name, 0); if (cname == NULL) { - JNU_ThrowOutOfMemoryError(env, NULL); return NULL; } // Copy name Skipping PREFIX
--- a/src/share/native/java/lang/System.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/native/java/lang/System.c Fri Nov 11 13:33:15 2016 +0000 @@ -56,44 +56,56 @@ return JVM_IHashCode(env, x); } -#define PUTPROP(props, key, val) \ - if (1) { \ - jstring jkey = (*env)->NewStringUTF(env, key); \ - jstring jval = (*env)->NewStringUTF(env, val); \ - jobject r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \ - if ((*env)->ExceptionOccurred(env)) return NULL; \ - (*env)->DeleteLocalRef(env, jkey); \ - (*env)->DeleteLocalRef(env, jval); \ - (*env)->DeleteLocalRef(env, r); \ +#define PUTPROP(props, key, val) \ + if (1) { \ + jstring jkey, jval; \ + jobject r; \ + jkey = (*env)->NewStringUTF(env, key); \ + if (jkey == NULL) return NULL; \ + jval = (*env)->NewStringUTF(env, val); \ + if (jval == NULL) return NULL; \ + r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \ + if ((*env)->ExceptionOccurred(env)) return NULL; \ + (*env)->DeleteLocalRef(env, jkey); \ + (*env)->DeleteLocalRef(env, jval); \ + (*env)->DeleteLocalRef(env, r); \ } else ((void) 0) /* "key" is a char type string with only ASCII character in it. "val" is a nchar (typedefed in java_props.h) type string */ -#define PUTPROP_ForPlatformNString(props, key, val) \ - if (1) { \ - jstring jkey = (*env)->NewStringUTF(env, key); \ - jstring jval = GetStringPlatform(env, val); \ - jobject r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \ - if ((*env)->ExceptionOccurred(env)) return NULL; \ - (*env)->DeleteLocalRef(env, jkey); \ - (*env)->DeleteLocalRef(env, jval); \ - (*env)->DeleteLocalRef(env, r); \ +#define PUTPROP_ForPlatformNString(props, key, val) \ + if (1) { \ + jstring jkey, jval; \ + jobject r; \ + jkey = (*env)->NewStringUTF(env, key); \ + if (jkey == NULL) return NULL; \ + jval = GetStringPlatform(env, val); \ + if (jval == NULL) return NULL; \ + r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \ + if ((*env)->ExceptionOccurred(env)) return NULL; \ + (*env)->DeleteLocalRef(env, jkey); \ + (*env)->DeleteLocalRef(env, jval); \ + (*env)->DeleteLocalRef(env, r); \ } else ((void) 0) -#define REMOVEPROP(props, key) \ - if (1) { \ - jstring jkey = JNU_NewStringPlatform(env, key); \ - jobject r = (*env)->CallObjectMethod(env, props, removeID, jkey); \ - if ((*env)->ExceptionOccurred(env)) return NULL; \ - (*env)->DeleteLocalRef(env, jkey); \ - (*env)->DeleteLocalRef(env, r); \ +#define REMOVEPROP(props, key) \ + if (1) { \ + jstring jkey; \ + jobject r; \ + jkey = JNU_NewStringPlatform(env, key); \ + if (jkey == NULL) return NULL; \ + r = (*env)->CallObjectMethod(env, props, removeID, jkey); \ + if ((*env)->ExceptionOccurred(env)) return NULL; \ + (*env)->DeleteLocalRef(env, jkey); \ + (*env)->DeleteLocalRef(env, r); \ } else ((void) 0) -#define GETPROP(props, key, jret) \ - if (1) { \ - jstring jkey = JNU_NewStringPlatform(env, key); \ +#define GETPROP(props, key, jret) \ + if (1) { \ + jstring jkey = JNU_NewStringPlatform(env, key); \ + if (jkey == NULL) return NULL; \ jret = (*env)->CallObjectMethod(env, props, getPropID, jkey); \ - if ((*env)->ExceptionOccurred(env)) return NULL; \ - (*env)->DeleteLocalRef(env, jkey); \ + if ((*env)->ExceptionOccurred(env)) return NULL; \ + (*env)->DeleteLocalRef(env, jkey); \ } else ((void) 0) #ifndef VENDOR /* Third party may overwrite this. */ @@ -169,23 +181,31 @@ Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props) { char buf[128]; - java_props_t *sprops = GetJavaProperties(env); - jmethodID putID = (*env)->GetMethodID(env, - (*env)->GetObjectClass(env, props), - "put", - "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); - jmethodID removeID = (*env)->GetMethodID(env, - (*env)->GetObjectClass(env, props), - "remove", - "(Ljava/lang/Object;)Ljava/lang/Object;"); - jmethodID getPropID = (*env)->GetMethodID(env, - (*env)->GetObjectClass(env, props), - "getProperty", - "(Ljava/lang/String;)Ljava/lang/String;"); + java_props_t *sprops; + jmethodID putID, removeID, getPropID; jobject ret = NULL; jstring jVMVal = NULL; - if (sprops == NULL || putID == NULL ) return NULL; + sprops = GetJavaProperties(env); + CHECK_NULL_RETURN(sprops, NULL); + + putID = (*env)->GetMethodID(env, + (*env)->GetObjectClass(env, props), + "put", + "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); + CHECK_NULL_RETURN(putID, NULL); + + removeID = (*env)->GetMethodID(env, + (*env)->GetObjectClass(env, props), + "remove", + "(Ljava/lang/Object;)Ljava/lang/Object;"); + CHECK_NULL_RETURN(removeID, NULL); + + getPropID = (*env)->GetMethodID(env, + (*env)->GetObjectClass(env, props), + "getProperty", + "(Ljava/lang/String;)Ljava/lang/String;"); + CHECK_NULL_RETURN(getPropID, NULL); PUTPROP(props, "java.specification.version", JDK_MAJOR_VERSION "." JDK_MINOR_VERSION); @@ -382,6 +402,7 @@ GETPROP(props, "sun.locale.formatasdefault", jVMVal); if (jVMVal) { const char * val = (*env)->GetStringUTFChars(env, jVMVal, 0); + CHECK_NULL_RETURN(val, NULL); fmtdefault = !strcmp(val, "true"); (*env)->ReleaseStringUTFChars(env, jVMVal, val); (*env)->DeleteLocalRef(env, jVMVal);
--- a/src/share/native/java/net/Inet4Address.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/native/java/net/Inet4Address.c Fri Nov 11 13:33:15 2016 +0000 @@ -34,6 +34,8 @@ jclass ia4_class; jmethodID ia4_ctrID; +static int ia4_initialized = 0; + /* * Class: java_net_Inet4Address * Method: init @@ -41,9 +43,13 @@ */ JNIEXPORT void JNICALL Java_java_net_Inet4Address_init(JNIEnv *env, jclass cls) { - jclass c = (*env)->FindClass(env, "java/net/Inet4Address"); - CHECK_NULL(c); - ia4_class = (*env)->NewGlobalRef(env, c); - CHECK_NULL(ia4_class); - ia4_ctrID = (*env)->GetMethodID(env, ia4_class, "<init>", "()V"); + if (!ia4_initialized) { + jclass c = (*env)->FindClass(env, "java/net/Inet4Address"); + CHECK_NULL(c); + ia4_class = (*env)->NewGlobalRef(env, c); + CHECK_NULL(ia4_class); + ia4_ctrID = (*env)->GetMethodID(env, ia4_class, "<init>", "()V"); + CHECK_NULL(ia4_ctrID); + ia4_initialized = 1; + } }
--- a/src/share/native/java/net/Inet6Address.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/native/java/net/Inet6Address.c Fri Nov 11 13:33:15 2016 +0000 @@ -42,6 +42,8 @@ jfieldID ia6_scopeifnameID; jmethodID ia6_ctrID; +static int ia6_initialized = 0; + /* * Class: java_net_Inet6Address * Method: init @@ -49,24 +51,28 @@ */ JNIEXPORT void JNICALL Java_java_net_Inet6Address_init(JNIEnv *env, jclass cls) { - jclass ia6h_class; - jclass c = (*env)->FindClass(env, "java/net/Inet6Address"); - CHECK_NULL(c); - ia6_class = (*env)->NewGlobalRef(env, c); - CHECK_NULL(ia6_class); - ia6h_class = (*env)->FindClass(env, "java/net/Inet6Address$Inet6AddressHolder"); - CHECK_NULL(ia6h_class); - ia6_holder6ID = (*env)->GetFieldID(env, ia6_class, "holder6", "Ljava/net/Inet6Address$Inet6AddressHolder;"); - CHECK_NULL(ia6_holder6ID); - ia6_ipaddressID = (*env)->GetFieldID(env, ia6h_class, "ipaddress", "[B"); - CHECK_NULL(ia6_ipaddressID); - ia6_scopeidID = (*env)->GetFieldID(env, ia6h_class, "scope_id", "I"); - CHECK_NULL(ia6_scopeidID); - ia6_cachedscopeidID = (*env)->GetFieldID(env, ia6_class, "cached_scope_id", "I"); - CHECK_NULL(ia6_cachedscopeidID); - ia6_scopeidsetID = (*env)->GetFieldID(env, ia6h_class, "scope_id_set", "Z"); - CHECK_NULL(ia6_scopeidsetID); - ia6_scopeifnameID = (*env)->GetFieldID(env, ia6h_class, "scope_ifname", "Ljava/net/NetworkInterface;"); - CHECK_NULL(ia6_scopeifnameID); - ia6_ctrID = (*env)->GetMethodID(env, ia6_class, "<init>", "()V"); + if (!ia6_initialized) { + jclass ia6h_class; + jclass c = (*env)->FindClass(env, "java/net/Inet6Address"); + CHECK_NULL(c); + ia6_class = (*env)->NewGlobalRef(env, c); + CHECK_NULL(ia6_class); + ia6h_class = (*env)->FindClass(env, "java/net/Inet6Address$Inet6AddressHolder"); + CHECK_NULL(ia6h_class); + ia6_holder6ID = (*env)->GetFieldID(env, ia6_class, "holder6", "Ljava/net/Inet6Address$Inet6AddressHolder;"); + CHECK_NULL(ia6_holder6ID); + ia6_ipaddressID = (*env)->GetFieldID(env, ia6h_class, "ipaddress", "[B"); + CHECK_NULL(ia6_ipaddressID); + ia6_scopeidID = (*env)->GetFieldID(env, ia6h_class, "scope_id", "I"); + CHECK_NULL(ia6_scopeidID); + ia6_cachedscopeidID = (*env)->GetFieldID(env, ia6_class, "cached_scope_id", "I"); + CHECK_NULL(ia6_cachedscopeidID); + ia6_scopeidsetID = (*env)->GetFieldID(env, ia6h_class, "scope_id_set", "Z"); + CHECK_NULL(ia6_scopeidsetID); + ia6_scopeifnameID = (*env)->GetFieldID(env, ia6h_class, "scope_ifname", "Ljava/net/NetworkInterface;"); + CHECK_NULL(ia6_scopeifnameID); + ia6_ctrID = (*env)->GetMethodID(env, ia6_class, "<init>", "()V"); + CHECK_NULL(ia6_ctrID); + ia6_initialized = 1; + } }
--- a/src/share/native/java/net/InetAddress.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/native/java/net/InetAddress.c Fri Nov 11 13:33:15 2016 +0000 @@ -41,6 +41,8 @@ jfieldID iac_origHostNameID; jfieldID ia_preferIPv6AddressID; +static int ia_initialized = 0; + /* * Class: java_net_InetAddress * Method: init @@ -48,23 +50,28 @@ */ JNIEXPORT void JNICALL Java_java_net_InetAddress_init(JNIEnv *env, jclass cls) { - jclass c = (*env)->FindClass(env,"java/net/InetAddress"); - CHECK_NULL(c); - ia_class = (*env)->NewGlobalRef(env, c); - CHECK_NULL(ia_class); - c = (*env)->FindClass(env,"java/net/InetAddress$InetAddressHolder"); - CHECK_NULL(c); - iac_class = (*env)->NewGlobalRef(env, c); - ia_holderID = (*env)->GetFieldID(env, ia_class, "holder", "Ljava/net/InetAddress$InetAddressHolder;"); - CHECK_NULL(ia_holderID); - ia_preferIPv6AddressID = (*env)->GetStaticFieldID(env, ia_class, "preferIPv6Address", "Z"); - CHECK_NULL(ia_preferIPv6AddressID); + if (!ia_initialized) { + jclass c = (*env)->FindClass(env,"java/net/InetAddress"); + CHECK_NULL(c); + ia_class = (*env)->NewGlobalRef(env, c); + CHECK_NULL(ia_class); + c = (*env)->FindClass(env,"java/net/InetAddress$InetAddressHolder"); + CHECK_NULL(c); + iac_class = (*env)->NewGlobalRef(env, c); + CHECK_NULL(iac_class); + ia_holderID = (*env)->GetFieldID(env, ia_class, "holder", "Ljava/net/InetAddress$InetAddressHolder;"); + CHECK_NULL(ia_holderID); + ia_preferIPv6AddressID = (*env)->GetStaticFieldID(env, ia_class, "preferIPv6Address", "Z"); + CHECK_NULL(ia_preferIPv6AddressID); - iac_addressID = (*env)->GetFieldID(env, iac_class, "address", "I"); - CHECK_NULL(iac_addressID); - iac_familyID = (*env)->GetFieldID(env, iac_class, "family", "I"); - CHECK_NULL(iac_familyID); - iac_hostNameID = (*env)->GetFieldID(env, iac_class, "hostName", "Ljava/lang/String;"); - CHECK_NULL(iac_hostNameID); - iac_origHostNameID = (*env)->GetFieldID(env, iac_class, "originalHostName", "Ljava/lang/String;"); + iac_addressID = (*env)->GetFieldID(env, iac_class, "address", "I"); + CHECK_NULL(iac_addressID); + iac_familyID = (*env)->GetFieldID(env, iac_class, "family", "I"); + CHECK_NULL(iac_familyID); + iac_hostNameID = (*env)->GetFieldID(env, iac_class, "hostName", "Ljava/lang/String;"); + CHECK_NULL(iac_hostNameID); + iac_origHostNameID = (*env)->GetFieldID(env, iac_class, "originalHostName", "Ljava/lang/String;"); + CHECK_NULL(iac_origHostNameID); + ia_initialized = 1; + } }
--- a/src/share/native/java/net/net_util.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/native/java/net/net_util.c Fri Nov 11 13:33:15 2016 +0000 @@ -75,11 +75,14 @@ static int initialized = 0; -static void initInetAddrs(JNIEnv *env) { +JNIEXPORT void JNICALL initInetAddressIDs(JNIEnv *env) { if (!initialized) { Java_java_net_InetAddress_init(env, 0); + JNU_CHECK_EXCEPTION(env); Java_java_net_Inet4Address_init(env, 0); + JNU_CHECK_EXCEPTION(env); Java_java_net_Inet6Address_init(env, 0); + JNU_CHECK_EXCEPTION(env); initialized = 1; } } @@ -100,47 +103,32 @@ * get_ methods that return objects return NULL on error. */ jobject getInet6Address_scopeifname(JNIEnv *env, jobject iaObj) { - jobject holder; - - initInetAddrs(env); - holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); + jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); CHECK_NULL_RETURN(holder, NULL); return (*env)->GetObjectField(env, holder, ia6_scopeifnameID); } int setInet6Address_scopeifname(JNIEnv *env, jobject iaObj, jobject scopeifname) { - jobject holder; - - initInetAddrs(env); - holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); + jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); CHECK_NULL_RETURN(holder, JNI_FALSE); (*env)->SetObjectField(env, holder, ia6_scopeifnameID, scopeifname); return JNI_TRUE; } int getInet6Address_scopeid_set(JNIEnv *env, jobject iaObj) { - jobject holder; - - initInetAddrs(env); - holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); + jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); CHECK_NULL_RETURN(holder, -1); return (*env)->GetBooleanField(env, holder, ia6_scopeidsetID); } int getInet6Address_scopeid(JNIEnv *env, jobject iaObj) { - jobject holder; - - initInetAddrs(env); - holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); + jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); CHECK_NULL_RETURN(holder, -1); return (*env)->GetIntField(env, holder, ia6_scopeidID); } int setInet6Address_scopeid(JNIEnv *env, jobject iaObj, int scopeid) { - jobject holder; - - initInetAddrs(env); - holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); + jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); CHECK_NULL_RETURN(holder, JNI_FALSE); (*env)->SetIntField(env, holder, ia6_scopeidID, scopeid); if (scopeid > 0) { @@ -154,7 +142,6 @@ jobject holder, addr; jbyteArray barr; - initInetAddrs(env); holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); CHECK_NULL_RETURN(holder, JNI_FALSE); addr = (*env)->GetObjectField(env, holder, ia6_ipaddressID); @@ -167,7 +154,6 @@ jobject holder; jbyteArray addr; - initInetAddrs(env); holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); CHECK_NULL_RETURN(holder, JNI_FALSE); addr = (jbyteArray)(*env)->GetObjectField(env, holder, ia6_ipaddressID); @@ -181,53 +167,39 @@ } void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address) { - jobject holder; - initInetAddrs(env); - holder = (*env)->GetObjectField(env, iaObj, ia_holderID); + jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); (*env)->SetIntField(env, holder, iac_addressID, address); } void setInetAddress_family(JNIEnv *env, jobject iaObj, int family) { - jobject holder; - initInetAddrs(env); - holder = (*env)->GetObjectField(env, iaObj, ia_holderID); + jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); (*env)->SetIntField(env, holder, iac_familyID, family); } void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject host) { - jobject holder; - initInetAddrs(env); - holder = (*env)->GetObjectField(env, iaObj, ia_holderID); + jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); (*env)->SetObjectField(env, holder, iac_hostNameID, host); (*env)->SetObjectField(env, holder, iac_origHostNameID, host); } int getInetAddress_addr(JNIEnv *env, jobject iaObj) { - jobject holder; - initInetAddrs(env); - holder = (*env)->GetObjectField(env, iaObj, ia_holderID); + jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); return (*env)->GetIntField(env, holder, iac_addressID); } int getInetAddress_family(JNIEnv *env, jobject iaObj) { - jobject holder; - - initInetAddrs(env); - holder = (*env)->GetObjectField(env, iaObj, ia_holderID); + jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); return (*env)->GetIntField(env, holder, iac_familyID); } jobject getInetAddress_hostName(JNIEnv *env, jobject iaObj) { - jobject holder; - initInetAddrs(env); - holder = (*env)->GetObjectField(env, iaObj, ia_holderID); + jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); return (*env)->GetObjectField(env, holder, iac_hostNameID); } JNIEXPORT jobject JNICALL NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) { jobject iaObj; - initInetAddrs(env); #ifdef AF_INET6 if (him->sa_family == AF_INET6) { jbyteArray ipaddress; @@ -239,31 +211,15 @@ jbyte *caddr = (jbyte *)&(him6->sin6_addr); if (NET_IsIPv4Mapped(caddr)) { int address; - static jclass inet4Cls = 0; - if (inet4Cls == 0) { - jclass c = (*env)->FindClass(env, "java/net/Inet4Address"); - CHECK_NULL_RETURN(c, NULL); - inet4Cls = (*env)->NewGlobalRef(env, c); - CHECK_NULL_RETURN(inet4Cls, NULL); - (*env)->DeleteLocalRef(env, c); - } - iaObj = (*env)->NewObject(env, inet4Cls, ia4_ctrID); + iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); CHECK_NULL_RETURN(iaObj, NULL); address = NET_IPv4MappedToIPv4(caddr); setInetAddress_addr(env, iaObj, address); setInetAddress_family(env, iaObj, IPv4); } else { - static jclass inet6Cls = 0; jint scope; int ret; - if (inet6Cls == 0) { - jclass c = (*env)->FindClass(env, "java/net/Inet6Address"); - CHECK_NULL_RETURN(c, NULL); - inet6Cls = (*env)->NewGlobalRef(env, c); - CHECK_NULL_RETURN(inet6Cls, NULL); - (*env)->DeleteLocalRef(env, c); - } - iaObj = (*env)->NewObject(env, inet6Cls, ia6_ctrID); + iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); CHECK_NULL_RETURN(iaObj, NULL); ret = setInet6Address_ipaddress(env, iaObj, (char *)&(him6->sin6_addr)); CHECK_NULL_RETURN(ret, NULL); @@ -276,16 +232,7 @@ #endif /* AF_INET6 */ { struct sockaddr_in *him4 = (struct sockaddr_in *)him; - static jclass inet4Cls = 0; - - if (inet4Cls == 0) { - jclass c = (*env)->FindClass(env, "java/net/Inet4Address"); - CHECK_NULL_RETURN(c, NULL); - inet4Cls = (*env)->NewGlobalRef(env, c); - CHECK_NULL_RETURN(inet4Cls, NULL); - (*env)->DeleteLocalRef(env, c); - } - iaObj = (*env)->NewObject(env, inet4Cls, ia4_ctrID); + iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); CHECK_NULL_RETURN(iaObj, NULL); setInetAddress_family(env, iaObj, IPv4); setInetAddress_addr(env, iaObj, ntohl(him4->sin_addr.s_addr));
--- a/src/share/native/java/net/net_util.h Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/native/java/net/net_util.h Fri Nov 11 13:33:15 2016 +0000 @@ -56,6 +56,8 @@ extern jfieldID iac_origHostNameID; extern jfieldID ia_preferIPv6AddressID; +JNIEXPORT void JNICALL initInetAddressIDs(JNIEnv *env); + /** (Inet6Address accessors) * set_ methods return JNI_TRUE on success JNI_FALSE on error * get_ methods that return int/boolean, return -1 on error
--- a/src/share/native/java/nio/Bits.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/native/java/nio/Bits.c Fri Nov 11 13:33:15 2016 +0000 @@ -51,10 +51,13 @@ #define MBYTE 1048576 -#define GETCRITICAL(bytes, env, obj) { \ +#define GETCRITICAL_OR_RETURN(bytes, env, obj) { \ bytes = (*env)->GetPrimitiveArrayCritical(env, obj, NULL); \ - if (bytes == NULL) \ - JNU_ThrowInternalError(env, "Unable to get array"); \ + if (bytes == NULL) { \ + if ((*env)->ExceptionOccurred(env) == NULL) \ + JNU_ThrowInternalError(env, "Unable to get array"); \ + return; \ + } \ } #define RELEASECRITICAL(bytes, env, obj, mode) { \ @@ -85,7 +88,7 @@ else size = (size_t)length; - GETCRITICAL(bytes, env, src); + GETCRITICAL_OR_RETURN(bytes, env, src); srcShort = (jshort *)(bytes + srcPos); endShort = srcShort + (size / sizeof(jshort)); @@ -120,7 +123,7 @@ else size = (size_t)length; - GETCRITICAL(bytes, env, dst); + GETCRITICAL_OR_RETURN(bytes, env, dst); dstShort = (jshort *)(bytes + dstPos); endShort = srcShort + (size / sizeof(jshort)); @@ -155,7 +158,7 @@ else size = (size_t)length; - GETCRITICAL(bytes, env, src); + GETCRITICAL_OR_RETURN(bytes, env, src); srcInt = (jint *)(bytes + srcPos); endInt = srcInt + (size / sizeof(jint)); @@ -190,7 +193,7 @@ else size = (size_t)length; - GETCRITICAL(bytes, env, dst); + GETCRITICAL_OR_RETURN(bytes, env, dst); dstInt = (jint *)(bytes + dstPos); endInt = srcInt + (size / sizeof(jint)); @@ -225,7 +228,7 @@ else size = (size_t)length; - GETCRITICAL(bytes, env, src); + GETCRITICAL_OR_RETURN(bytes, env, src); srcLong = (jlong *)(bytes + srcPos); endLong = srcLong + (size / sizeof(jlong)); @@ -260,7 +263,7 @@ else size = (size_t)length; - GETCRITICAL(bytes, env, dst); + GETCRITICAL_OR_RETURN(bytes, env, dst); dstLong = (jlong *)(bytes + dstPos); endLong = srcLong + (size / sizeof(jlong));
--- a/src/share/native/sun/misc/VMSupport.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/share/native/sun/misc/VMSupport.c Fri Nov 11 13:33:15 2016 +0000 @@ -42,6 +42,7 @@ if (!JDK_InitJvmHandle()) { JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup"); + return NULL; } InitAgentProperties_fp = (INIT_AGENT_PROPERTIES_FN) JDK_FindJvmEntry("JVM_InitAgentProperties");
--- a/src/solaris/native/com/sun/security/auth/module/Solaris.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/com/sun/security/auth/module/Solaris.c Fri Nov 11 13:33:15 2016 +0000 @@ -32,6 +32,12 @@ #include <string.h> #include <pwd.h> +static void throwIllegalArgumentException(JNIEnv *env, const char *msg) { + jclass clazz = (*env)->FindClass(env, "java/lang/IllegalArgumentException"); + if (clazz != NULL) + (*env)->ThrowNew(env, clazz, msg); +} + JNIEXPORT void JNICALL Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo (JNIEnv *env, jobject obj) { @@ -51,7 +57,7 @@ if (groups == NULL) { jclass cls = (*env)->FindClass(env,"java/lang/OutOfMemoryError"); - if(cls != 0) + if (cls != NULL) (*env)->ThrowNew(env, cls, NULL); return; } @@ -67,15 +73,13 @@ */ fid = (*env)->GetFieldID(env, cls, "username", "Ljava/lang/String;"); if (fid == 0) { - jclass newExcCls = - (*env)->FindClass(env, "java/lang/IllegalArgumentException"); - if (newExcCls == 0) { - /* Unable to find the new exception class, give up. */ - return; - } - (*env)->ThrowNew(env, newExcCls, "invalid field: username"); + (*env)->ExceptionClear(env); + throwIllegalArgumentException(env, "invalid field: username"); + return; } jstr = (*env)->NewStringUTF(env, pwd.pw_name); + if (jstr == NULL) + return; (*env)->SetObjectField(env, obj, fid, jstr); /* @@ -83,13 +87,9 @@ */ fid = (*env)->GetFieldID(env, cls, "uid", "J"); if (fid == 0) { - jclass newExcCls = - (*env)->FindClass(env, "java/lang/IllegalArgumentException"); - if (newExcCls == 0) { - /* Unable to find the new exception class, give up. */ - return; - } - (*env)->ThrowNew(env, newExcCls, "invalid field: username"); + (*env)->ExceptionClear(env); + throwIllegalArgumentException(env, "invalid field: uid"); + return; } (*env)->SetLongField(env, obj, fid, pwd.pw_uid); @@ -98,13 +98,9 @@ */ fid = (*env)->GetFieldID(env, cls, "gid", "J"); if (fid == 0) { - jclass newExcCls = - (*env)->FindClass(env, "java/lang/IllegalArgumentException"); - if (newExcCls == 0) { - /* Unable to find the new exception class, give up. */ - return; - } - (*env)->ThrowNew(env, newExcCls, "invalid field: username"); + (*env)->ExceptionClear(env); + throwIllegalArgumentException(env, "invalid field: gid"); + return; } (*env)->SetLongField(env, obj, fid, pwd.pw_gid); @@ -113,17 +109,17 @@ */ fid = (*env)->GetFieldID(env, cls, "groups", "[J"); if (fid == 0) { - jclass newExcCls = - (*env)->FindClass(env, "java/lang/IllegalArgumentException"); - if (newExcCls == 0) { - /* Unable to find the new exception class, give up. */ - return; - } - (*env)->ThrowNew(env, newExcCls, "invalid field: username"); + (*env)->ExceptionClear(env); + throwIllegalArgumentException(env, "invalid field: groups"); + return; } jgroups = (*env)->NewLongArray(env, numSuppGroups); + if (jgroups == NULL) + return; jgroupsAsArray = (*env)->GetLongArrayElements(env, jgroups, 0); + if (jgroupsAsArray == NULL) + return; for (i = 0; i < numSuppGroups; i++) jgroupsAsArray[i] = groups[i]; (*env)->ReleaseLongArrayElements(env, jgroups, jgroupsAsArray, 0);
--- a/src/solaris/native/com/sun/security/auth/module/Unix.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/com/sun/security/auth/module/Unix.c Fri Nov 11 13:33:15 2016 +0000 @@ -60,7 +60,7 @@ groups = (gid_t *)calloc(numSuppGroups, sizeof(gid_t)); if (groups == NULL) { jclass cls = (*env)->FindClass(env,"java/lang/OutOfMemoryError"); - if(cls != 0) + if (cls != NULL) (*env)->ThrowNew(env, cls, NULL); return; } @@ -90,6 +90,8 @@ goto cleanUpAndReturn; jstr = (*env)->NewStringUTF(env, pwd->pw_name); + if (jstr == NULL) + goto cleanUpAndReturn; (*env)->SetObjectField(env, obj, userNameID, jstr); (*env)->SetLongField(env, obj, userID, pwd->pw_uid); @@ -97,7 +99,11 @@ (*env)->SetLongField(env, obj, groupID, pwd->pw_gid); jgroups = (*env)->NewLongArray(env, numSuppGroups); + if (jgroups == NULL) + goto cleanUpAndReturn; jgroupsAsArray = (*env)->GetLongArrayElements(env, jgroups, 0); + if (jgroupsAsArray == NULL) + goto cleanUpAndReturn; for (i = 0; i < numSuppGroups; i++) jgroupsAsArray[i] = groups[i]; (*env)->ReleaseLongArrayElements(env, jgroups, jgroupsAsArray, 0);
--- a/src/solaris/native/java/io/FileDescriptor_md.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/java/io/FileDescriptor_md.c Fri Nov 11 13:33:15 2016 +0000 @@ -23,9 +23,11 @@ * questions. */ +#include "jni.h" +#include "jni_util.h" #include "jvm.h" + #include "io_util_md.h" - #include "java_io_FileDescriptor.h" /*******************************************************************/ @@ -41,7 +43,7 @@ JNIEXPORT void JNICALL Java_java_io_FileDescriptor_initIDs(JNIEnv *env, jclass fdClass) { - IO_fd_fdID = (*env)->GetFieldID(env, fdClass, "fd", "I"); + CHECK_NULL(IO_fd_fdID = (*env)->GetFieldID(env, fdClass, "fd", "I")); } /**************************************************************
--- a/src/solaris/native/java/lang/ProcessEnvironment_md.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/java/lang/ProcessEnvironment_md.c Fri Nov 11 13:33:15 2016 +0000 @@ -53,6 +53,7 @@ jsize i, j; jobjectArray result; jclass byteArrCls = (*env)->FindClass(env, "[B"); + CHECK_NULL_RETURN(byteArrCls, NULL); for (i = 0; environ[i]; i++) { /* Ignore corrupted environment variables */ @@ -61,7 +62,7 @@ } result = (*env)->NewObjectArray(env, 2*count, byteArrCls, 0); - if (result == NULL) return NULL; + CHECK_NULL_RETURN(result, NULL); for (i = 0, j = 0; environ[i]; i++) { const char * varEnd = strchr(environ[i], '='); @@ -72,9 +73,9 @@ jsize varLength = varEnd - environ[i]; jsize valLength = strlen(valBeg); var = (*env)->NewByteArray(env, varLength); - if (var == NULL) return NULL; + CHECK_NULL_RETURN(var, NULL); val = (*env)->NewByteArray(env, valLength); - if (val == NULL) return NULL; + CHECK_NULL_RETURN(val, NULL); (*env)->SetByteArrayRegion(env, var, 0, varLength, (jbyte*) environ[i]); (*env)->SetByteArrayRegion(env, val, 0, valLength,
--- a/src/solaris/native/java/lang/UNIXProcess_md.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/java/lang/UNIXProcess_md.c Fri Nov 11 13:33:15 2016 +0000 @@ -206,6 +206,7 @@ Java_java_lang_UNIXProcess_init(JNIEnv *env, jclass clazz) { parentPathv = effectivePathv(env); + CHECK_NULL(parentPathv); setSIGCHLDHandler(env); }
--- a/src/solaris/native/java/lang/java_props_md.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/java/lang/java_props_md.c Fri Nov 11 13:33:15 2016 +0000 @@ -546,6 +546,9 @@ sprops.display_country = sprops.country; sprops.display_variant = sprops.variant; + /* ParseLocale failed with OOME */ + JNU_CHECK_EXCEPTION_RETURN(env, NULL); + #ifdef MACOSX sprops.sun_jnu_encoding = "UTF-8"; #else
--- a/src/solaris/native/java/net/ExtendedOptionsImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/java/net/ExtendedOptionsImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -88,6 +88,7 @@ /* SocketFlow fields */ c = (*env)->FindClass(env, "jdk/net/SocketFlow"); + CHECK_NULL(c); /* status */
--- a/src/solaris/native/java/net/Inet4AddressImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/java/net/Inet4AddressImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -51,29 +51,6 @@ #define HAS_GLIBC_GETHOSTBY_R 1 #endif -static jclass ni_iacls; -static jclass ni_ia4cls; -static jmethodID ni_ia4ctrID; - -static jboolean initializeInetClasses(JNIEnv *env) -{ - static int initialized = 0; - if (!initialized) { - ni_iacls = (*env)->FindClass(env, "java/net/InetAddress"); - CHECK_NULL_RETURN(ni_iacls, JNI_FALSE); - ni_iacls = (*env)->NewGlobalRef(env, ni_iacls); - CHECK_NULL_RETURN(ni_iacls, JNI_FALSE); - ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address"); - CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE); - ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls); - CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE); - ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V"); - CHECK_NULL_RETURN(ni_ia4ctrID, JNI_FALSE); - initialized = 1; - } - return JNI_TRUE; -} - #if defined(_ALLBSD_SOURCE) && !defined(HAS_GLIBC_GETHOSTBY_R) extern jobjectArray lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6); @@ -147,8 +124,8 @@ int getaddrinfo_error=0; struct addrinfo hints, *res, *resNew = NULL; - if (!initializeInetClasses(env)) - return NULL; + initInetAddressIDs(env); + JNU_CHECK_EXCEPTION_RETURN(env, NULL); if (IS_NULL(host)) { JNU_ThrowNullPointerException(env, "host is null"); @@ -242,7 +219,7 @@ goto cleanupAndReturn; } - ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL); + ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL); if (IS_NULL(ret)) { /* we may have memory to free at the end of this */ goto cleanupAndReturn; @@ -252,7 +229,7 @@ /* We need 4 bytes to store ipv4 address; */ int len = 4; - jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); + jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (IS_NULL(iaObj)) { /* we may have memory to free at the end of this */ ret = NULL; @@ -408,8 +385,8 @@ int error = 0; struct addrinfo hints, *res, *resNew = NULL; - if (!initializeInetClasses(env)) - return NULL; + initInetAddressIDs(env); + JNU_CHECK_EXCEPTION_RETURN(env, NULL); if (IS_NULL(host)) { JNU_ThrowNullPointerException(env, "host is null"); @@ -487,7 +464,7 @@ retLen = i; iterator = resNew; - ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL); + ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL); if (IS_NULL(ret)) { /* we may have memory to free at the end of this */ @@ -496,7 +473,7 @@ i = 0; while (iterator != NULL) { - jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); + jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (IS_NULL(iaObj)) { ret = NULL; goto cleanupAndReturn;
--- a/src/solaris/native/java/net/Inet6AddressImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/java/net/Inet6AddressImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -117,44 +117,6 @@ return (*env)->NewStringUTF(env, hostname); } -static jclass ni_iacls; -static jclass ni_ia4cls; -static jclass ni_ia6cls; -static jmethodID ni_ia4ctrID; -static jmethodID ni_ia6ctrID; -static jboolean preferIPv6Address; - -static jboolean initializeInetClasses(JNIEnv *env) -{ - jfieldID ni_preferIPv6AddressID; - static int initialized = 0; - if (!initialized) { - ni_iacls = (*env)->FindClass(env, "java/net/InetAddress"); - CHECK_NULL_RETURN(ni_iacls, JNI_FALSE); - ni_iacls = (*env)->NewGlobalRef(env, ni_iacls); - CHECK_NULL_RETURN(ni_iacls, JNI_FALSE); - ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address"); - CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE); - ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls); - CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE); - ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address"); - CHECK_NULL_RETURN(ni_ia6cls, JNI_FALSE); - ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls); - CHECK_NULL_RETURN(ni_ia6cls, JNI_FALSE); - ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V"); - CHECK_NULL_RETURN(ni_ia4ctrID, JNI_FALSE); - ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V"); - CHECK_NULL_RETURN(ni_ia6ctrID, JNI_FALSE); - ni_preferIPv6AddressID = - (*env)->GetStaticFieldID(env, ni_iacls, "preferIPv6Address", "Z"); - CHECK_NULL_RETURN(ni_preferIPv6AddressID, JNI_FALSE); - preferIPv6Address = - (*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID); - initialized = 1; - } - return JNI_TRUE; -} - #ifdef MACOSX /* also called from Inet4AddressImpl.c */ __private_extern__ jobjectArray @@ -169,9 +131,8 @@ jboolean includeLoopback = JNI_FALSE; jobject name; - // Make sure static variables we need are set. - if (!initializeInetClasses(env)) - return NULL; + initInetAddressIDs(env); + JNU_CHECK_EXCEPTION_RETURN(env, NULL); /* If the requested name matches this host's hostname, return IP addresses * from all attached interfaces. (#2844683 et al) This prevents undesired @@ -234,10 +195,10 @@ /* Create and fill the Java array. */ int arraySize = addrs4 + addrs6 - (includeLoopback ? 0 : (numV4Loopbacks + numV6Loopbacks)); - result = (*env)->NewObjectArray(env, arraySize, ni_iacls, NULL); + result = (*env)->NewObjectArray(env, arraySize, ia_class, NULL); if (!result) goto done; - if (preferIPv6Address) { + if ((*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID)) { i = includeLoopback ? addrs6 : (addrs6 - numV6Loopbacks); j = 0; } else { @@ -301,8 +262,8 @@ struct addrinfo hints, *res, *resNew = NULL; #endif /* AF_INET6 */ - if (!initializeInetClasses(env)) - return NULL; + initInetAddressIDs(env); + JNU_CHECK_EXCEPTION_RETURN(env, NULL); if (IS_NULL(host)) { JNU_ThrowNullPointerException(env, "host is null"); @@ -429,14 +390,14 @@ retLen = i; iterator = resNew; - ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL); + ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL); if (IS_NULL(ret)) { /* we may have memory to free at the end of this */ goto cleanupAndReturn; } - if (preferIPv6Address) { + if ((*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID)) { /* AF_INET addresses will be offset by inet6Count */ inetIndex = inet6Count; inet6Index = 0; @@ -449,7 +410,7 @@ while (iterator != NULL) { int ret1; if (iterator->ai_family == AF_INET) { - jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); + jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (IS_NULL(iaObj)) { ret = NULL; goto cleanupAndReturn; @@ -461,7 +422,7 @@ } else if (iterator->ai_family == AF_INET6) { jint scope = 0; - jobject iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID); + jobject iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); if (IS_NULL(iaObj)) { ret = NULL; goto cleanupAndReturn; @@ -555,6 +516,7 @@ if (!error) { ret = (*env)->NewStringUTF(env, host); + CHECK_NULL_RETURN(ret, NULL); } #endif /* AF_INET6 */
--- a/src/solaris/native/java/net/NetworkInterface.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/java/net/NetworkInterface.c Fri Nov 11 13:33:15 2016 +0000 @@ -133,12 +133,7 @@ jfieldID ni_defaultIndexID; jmethodID ni_ctrID; -static jclass ni_iacls; -static jclass ni_ia4cls; -static jclass ni_ia6cls; static jclass ni_ibcls; -static jmethodID ni_ia4ctrID; -static jmethodID ni_ia6ctrID; static jmethodID ni_ibctrID; static jfieldID ni_ibaddressID; static jfieldID ni_ib4broadcastID; @@ -215,26 +210,10 @@ CHECK_NULL(ni_parentID); ni_ctrID = (*env)->GetMethodID(env, ni_class, "<init>", "()V"); CHECK_NULL(ni_ctrID); - ni_iacls = (*env)->FindClass(env, "java/net/InetAddress"); - CHECK_NULL(ni_iacls); - ni_iacls = (*env)->NewGlobalRef(env, ni_iacls); - CHECK_NULL(ni_iacls); - ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address"); - CHECK_NULL(ni_ia4cls); - ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls); - CHECK_NULL(ni_ia4cls); - ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address"); - CHECK_NULL(ni_ia6cls); - ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls); - CHECK_NULL(ni_ia6cls); ni_ibcls = (*env)->FindClass(env, "java/net/InterfaceAddress"); CHECK_NULL(ni_ibcls); ni_ibcls = (*env)->NewGlobalRef(env, ni_ibcls); CHECK_NULL(ni_ibcls); - ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V"); - CHECK_NULL(ni_ia4ctrID); - ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V"); - CHECK_NULL(ni_ia6ctrID); ni_ibctrID = (*env)->GetMethodID(env, ni_ibcls, "<init>", "()V"); CHECK_NULL(ni_ibctrID); ni_ibaddressID = (*env)->GetFieldID(env, ni_ibcls, "address", @@ -247,6 +226,9 @@ CHECK_NULL(ni_ib4maskID); ni_defaultIndexID = (*env)->GetStaticFieldID(env, ni_class, "defaultIndex", "I"); + CHECK_NULL(ni_defaultIndexID); + + initInetAddressIDs(env); } /* @@ -700,7 +682,7 @@ } // create the array of InetAddresses - addrArr = (*env)->NewObjectArray(env, addr_count, ni_iacls, NULL); + addrArr = (*env)->NewObjectArray(env, addr_count, ia_class, NULL); if (addrArr == NULL) { return NULL; } @@ -717,7 +699,7 @@ jobject ibObj = NULL; if (addrP->family == AF_INET) { - iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); + iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (iaObj) { setInetAddress_addr(env, iaObj, htonl( ((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr)); @@ -729,7 +711,7 @@ (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj); if (addrP->brdcast) { jobject ia2Obj = NULL; - ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); + ia2Obj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (ia2Obj) { setInetAddress_addr(env, ia2Obj, htonl( ((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr)); @@ -747,7 +729,7 @@ #if defined(AF_INET6) if (addrP->family == AF_INET6) { int scope=0; - iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID); + iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); if (iaObj) { jboolean ret = setInet6Address_ipaddress(env, iaObj, (char *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr));
--- a/src/solaris/native/java/net/PlainDatagramSocketImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/java/net/PlainDatagramSocketImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -174,9 +174,8 @@ IO_fd_fdID = NET_GetFileDescriptorID(env); CHECK_NULL(IO_fd_fdID); - Java_java_net_InetAddress_init(env, 0); - Java_java_net_Inet4Address_init(env, 0); - Java_java_net_Inet6Address_init(env, 0); + initInetAddressIDs(env); + JNU_CHECK_EXCEPTION(env); Java_java_net_NetworkInterface_init(env, 0); }
--- a/src/solaris/native/java/net/PlainSocketImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/java/net/PlainSocketImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -162,6 +162,9 @@ IO_fd_fdID = NET_GetFileDescriptorID(env); CHECK_NULL(IO_fd_fdID); + initInetAddressIDs(env); + JNU_CHECK_EXCEPTION(env); + /* Create the marker fd used for dup2 */ marker_fd = getMarkerFD(); }
--- a/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -201,7 +201,7 @@ } if (senderAddr == NULL) { jobject isa = NULL; - int port; + int port = 0; jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port); if (ia != NULL) { isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port);
--- a/src/solaris/native/sun/nio/ch/IOUtil.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/sun/nio/ch/IOUtil.c Fri Nov 11 13:33:15 2016 +0000 @@ -35,6 +35,7 @@ #include "java_lang_Integer.h" #include "nio.h" #include "nio_util.h" +#include "net_util.h" static jfieldID fd_fdID; /* for jint 'fd' in java.io.FileDescriptor */ @@ -44,6 +45,7 @@ { CHECK_NULL(clazz = (*env)->FindClass(env, "java/io/FileDescriptor")); CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I")); + initInetAddressIDs(env); } JNIEXPORT jboolean JNICALL
--- a/src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -84,7 +84,7 @@ int alloc_len; jobject remote_ia = 0; jobject isa; - jint remote_port; + jint remote_port = 0; NET_AllocSockaddr(&sa, &alloc_len); if (sa == NULL) {
--- a/src/solaris/native/sun/nio/ch/sctp/SctpNet.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/sun/nio/ch/sctp/SctpNet.c Fri Nov 11 13:33:15 2016 +0000 @@ -157,6 +157,7 @@ } preCloseFD = sp[0]; close(sp[1]); + initInetAddressIDs(env); } /* @@ -430,7 +431,7 @@ paddr = addr_buf; for (i=0; i<addrCount; i++) { jobject ia, isa = NULL; - int port; + int port = 0; sap = (struct sockaddr*)addr_buf; ia = NET_SockaddrToInetAddress(env, sap, &port); if (ia != NULL) @@ -542,6 +543,7 @@ void *arg; int arglen; + memset((char *) &linger, 0, sizeof(linger)); if (mapSocketOption(opt, &klevel, &kopt) < 0) { JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Unsupported socket option"); @@ -599,7 +601,7 @@ (JNIEnv *env, jclass klass, jint fd, jint assocId, jobject iaObj, jint port) { struct sctp_setprim prim; struct sockaddr* sap = (struct sockaddr*)&prim.ssp_addr; - int sap_len; + int sap_len = sizeof(sap); if (NET_InetAddressToSockaddr(env, iaObj, port, sap, &sap_len, JNI_TRUE) != 0) { @@ -624,7 +626,7 @@ jobject iaObj, jint port, jboolean preferIPv6) { struct sctp_setpeerprim prim; struct sockaddr* sap = (struct sockaddr*)&prim.sspp_addr; - int sap_len; + int sap_len = sizeof(sap); if (NET_InetAddressToSockaddr(env, iaObj, port, sap, &sap_len, preferIPv6) != 0) {
--- a/src/solaris/native/sun/nio/fs/MacOSXNativeDispatcher.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/solaris/native/sun/nio/fs/MacOSXNativeDispatcher.c Fri Nov 11 13:33:15 2016 +0000 @@ -39,12 +39,15 @@ jint form) { jcharArray result = NULL; - char chars_buf[(PATH_MAX + 1) * 2]; // utf16 + zero padding + char *chars; CFMutableStringRef csref = CFStringCreateMutable(NULL, 0); if (csref == NULL) { JNU_ThrowOutOfMemoryError(env, "native heap"); - } else { - char *chars = (char*)(*env)->GetPrimitiveArrayCritical(env, path, 0); + return NULL; + } + chars = (char*)(*env)->GetPrimitiveArrayCritical(env, path, 0); + if (chars != NULL) { + char chars_buf[(PATH_MAX + 1) * 2]; // utf16 + zero padding jsize len = (*env)->GetArrayLength(env, path); CFStringAppendCharacters(csref, (const UniChar*)chars, len); (*env)->ReleasePrimitiveArrayCritical(env, path, chars, 0); @@ -53,24 +56,26 @@ if (len < PATH_MAX) { if (CFStringGetCString(csref, chars_buf, sizeof(chars_buf), kCFStringEncodingUTF16)) { result = (*env)->NewCharArray(env, len); - (*env)->SetCharArrayRegion(env, result, 0, len, (jchar*)&chars_buf); + if (result != NULL) { + (*env)->SetCharArrayRegion(env, result, 0, len, (jchar*)&chars_buf); + } } } else { int ulen = (len + 1) * 2; chars = malloc(ulen); if (chars == NULL) { - CFRelease(csref); JNU_ThrowOutOfMemoryError(env, "native heap"); - return result; } else { if (CFStringGetCString(csref, chars, ulen, kCFStringEncodingUTF16)) { result = (*env)->NewCharArray(env, len); - (*env)->SetCharArrayRegion(env, result, 0, len, (jchar*)chars); + if (result != NULL) { + (*env)->SetCharArrayRegion(env, result, 0, len, (jchar*)chars); + } } free(chars); } } - CFRelease(csref); } + CFRelease(csref); return result; }
--- a/src/windows/native/com/sun/security/auth/module/nt.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/com/sun/security/auth/module/nt.c Fri Nov 11 13:33:15 2016 +0000 @@ -43,6 +43,12 @@ BOOL getTextualSid(PSID pSid, LPTSTR TextualSid, LPDWORD lpdwBufferLen); void DisplayErrorText(DWORD dwLastError); +static void throwIllegalArgumentException(JNIEnv *env, const char *msg) { + jclass clazz = (*env)->FindClass(env, "java/lang/IllegalArgumentException"); + if (clazz != NULL) + (*env)->ThrowNew(env, clazz, msg); +} + JNIEXPORT jlong JNICALL Java_com_sun_security_auth_module_NTSystem_getImpersonationToken0 (JNIEnv *env, jobject obj) { @@ -62,7 +68,6 @@ long i, j = 0; HANDLE tokenHandle = INVALID_HANDLE_VALUE; - BOOL systemError = FALSE; LPTSTR userName = NULL; // user name LPTSTR userSid = NULL; // user sid @@ -116,70 +121,59 @@ fid = (*env)->GetFieldID(env, cls, "userName", "Ljava/lang/String;"); if (fid == 0) { - jclass newExcCls = - (*env)->FindClass(env, "java/lang/IllegalArgumentException"); - if (newExcCls == 0) { - // Unable to find exception class - systemError = TRUE; - goto out; - } - (*env)->ThrowNew(env, newExcCls, "invalid field: userName"); + (*env)->ExceptionClear(env); + throwIllegalArgumentException(env, "invalid field: userName"); + goto cleanup; } jstr = (*env)->NewStringUTF(env, userName); + if (jstr == NULL) + goto cleanup; (*env)->SetObjectField(env, obj, fid, jstr); fid = (*env)->GetFieldID(env, cls, "userSID", "Ljava/lang/String;"); if (fid == 0) { - jclass newExcCls = - (*env)->FindClass(env, "java/lang/IllegalArgumentException"); - if (newExcCls == 0) { - systemError = TRUE; - goto out; - } - (*env)->ThrowNew(env, newExcCls, "invalid field: userSID"); + (*env)->ExceptionClear(env); + throwIllegalArgumentException(env, "invalid field: userSID"); + goto cleanup; } jstr = (*env)->NewStringUTF(env, userSid); + if (jstr == NULL) + goto cleanup; (*env)->SetObjectField(env, obj, fid, jstr); fid = (*env)->GetFieldID(env, cls, "domain", "Ljava/lang/String;"); if (fid == 0) { - jclass newExcCls = - (*env)->FindClass(env, "java/lang/IllegalArgumentException"); - if (newExcCls == 0) { - systemError = TRUE; - goto out; - } - (*env)->ThrowNew(env, newExcCls, "invalid field: domain"); + (*env)->ExceptionClear(env); + throwIllegalArgumentException(env, "invalid field: domain"); + goto cleanup; } jstr = (*env)->NewStringUTF(env, domainName); + if (jstr == NULL) + goto cleanup; (*env)->SetObjectField(env, obj, fid, jstr); if (domainSid != NULL) { fid = (*env)->GetFieldID(env, cls, "domainSID", "Ljava/lang/String;"); if (fid == 0) { - jclass newExcCls = - (*env)->FindClass(env, "java/lang/IllegalArgumentException"); - if (newExcCls == 0) { - systemError = TRUE; - goto out; - } - (*env)->ThrowNew(env, newExcCls, "invalid field: domainSID"); + (*env)->ExceptionClear(env); + throwIllegalArgumentException(env, "invalid field: domainSID"); + goto cleanup; } jstr = (*env)->NewStringUTF(env, domainSid); + if (jstr == NULL) + goto cleanup; (*env)->SetObjectField(env, obj, fid, jstr); } fid = (*env)->GetFieldID(env, cls, "primaryGroupID", "Ljava/lang/String;"); if (fid == 0) { - jclass newExcCls = - (*env)->FindClass(env, "java/lang/IllegalArgumentException"); - if (newExcCls == 0) { - systemError = TRUE; - goto out; - } - (*env)->ThrowNew(env, newExcCls, "invalid field: PrimaryGroupID"); + (*env)->ExceptionClear(env); + throwIllegalArgumentException(env, "invalid field: PrimaryGroupID"); + goto cleanup; } jstr = (*env)->NewStringUTF(env, primaryGroup); + if (jstr == NULL) + goto cleanup; (*env)->SetObjectField(env, obj, fid, jstr); // primary group may or may not be part of supplementary groups @@ -204,19 +198,14 @@ fid = (*env)->GetFieldID(env, cls, "groupIDs", "[Ljava/lang/String;"); if (fid == 0) { - jclass newExcCls = - (*env)->FindClass(env, "java/lang/IllegalArgumentException"); - if (newExcCls == 0) { - systemError = TRUE; - goto out; - } - (*env)->ThrowNew(env, newExcCls, "invalid field: groupIDs"); + (*env)->ExceptionClear(env); + throwIllegalArgumentException(env, "groupIDs"); + goto cleanup; } stringClass = (*env)->FindClass(env, "java/lang/String"); - if (stringClass == 0) { - goto out; - } + if (stringClass == NULL) + goto cleanup; if (pIndex == -1) { // primary group not in groups array @@ -226,6 +215,8 @@ // allocate one less array entry and do not add into new array jgroups = (*env)->NewObjectArray(env, numGroups-1, stringClass, 0); } + if (jgroups == NULL) + goto cleanup; for (i = 0, j = 0; i < (long)numGroups; i++) { if (pIndex == i) { @@ -233,12 +224,14 @@ continue; } jstr = (*env)->NewStringUTF(env, groups[i]); + if (jstr == NULL) + goto cleanup; (*env)->SetObjectArrayElement(env, jgroups, j++, jstr); } (*env)->SetObjectField(env, obj, fid, jgroups); } -out: +cleanup: if (userName != NULL) { HeapFree(GetProcessHeap(), 0, userName); } @@ -264,11 +257,6 @@ } CloseHandle(tokenHandle); - if (systemError && debug) { - printf(" [getCurrent] System Error: "); - printf("unable to find IllegalArgumentException class\n"); - } - return; } @@ -336,7 +324,7 @@ DisplayErrorText(GetLastError()); } error = TRUE; - goto out; + goto cleanup; } if (debug) { @@ -369,7 +357,7 @@ DisplayErrorText(GetLastError()); } error = TRUE; - goto out; + goto cleanup; } if (debug) { @@ -411,7 +399,7 @@ DisplayErrorText(GetLastError()); } // ok not to have a domain SID (no error) - goto out; + goto cleanup; } bufSize = 0; @@ -422,7 +410,7 @@ printf(" [getUser] domainSid: %s\n", *domainSid); } -out: +cleanup: if (tokenUserInfo != NULL) { HeapFree(GetProcessHeap(), 0, tokenUserInfo); } @@ -466,7 +454,7 @@ DisplayErrorText(GetLastError()); } error = TRUE; - goto out; + goto cleanup; } if (debug) { @@ -481,7 +469,7 @@ printf(" [getPrimaryGroup] primaryGroup: %s\n", *primaryGroup); } -out: +cleanup: if (tokenGroupInfo != NULL) { HeapFree(GetProcessHeap(), 0, tokenGroupInfo); } @@ -519,7 +507,7 @@ DisplayErrorText(GetLastError()); } error = TRUE; - goto out; + goto cleanup; } if (debug) { @@ -528,7 +516,7 @@ if (tokenGroupInfo->GroupCount == 0) { // no groups - goto out; + goto cleanup; } // return group info @@ -545,7 +533,7 @@ } } -out: +cleanup: if (tokenGroupInfo != NULL) { HeapFree(GetProcessHeap(), 0, tokenGroupInfo); }
--- a/src/windows/native/java/lang/java_props_md.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/java/lang/java_props_md.c Fri Nov 11 13:33:15 2016 +0000 @@ -188,6 +188,7 @@ free(elems[index]); } } else { + free(ret); ret = NULL; }
--- a/src/windows/native/java/net/DualStackPlainSocketImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/java/net/DualStackPlainSocketImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -47,6 +47,7 @@ isa_class = (*env)->NewGlobalRef(env, cls); isa_ctorID = (*env)->GetMethodID(env, cls, "<init>", "(Ljava/net/InetAddress;I)V"); + CHECK_NULL(isa_ctorID); // implement read timeout with select. isRcvTimeoutSupported = 0;
--- a/src/windows/native/java/net/Inet4AddressImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/java/net/Inet4AddressImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -114,11 +114,6 @@ return JNU_NewStringPlatform(env, hostname); } -static jclass ni_iacls; -static jclass ni_ia4cls; -static jmethodID ni_ia4ctrID; -static int initialized = 0; - /* * Find an internet address for a given hostname. Not this this * code only works for addresses of type INET. The translation @@ -143,19 +138,8 @@ jobjectArray ret = NULL; - if (!initialized) { - ni_iacls = (*env)->FindClass(env, "java/net/InetAddress"); - CHECK_NULL_RETURN(ni_iacls, NULL); - ni_iacls = (*env)->NewGlobalRef(env, ni_iacls); - CHECK_NULL_RETURN(ni_iacls, NULL); - ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address"); - CHECK_NULL_RETURN(ni_ia4cls, NULL); - ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls); - CHECK_NULL_RETURN(ni_ia4cls, NULL); - ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V"); - CHECK_NULL_RETURN(ni_ia4ctrID, NULL); - initialized = 1; - } + initInetAddressIDs(env); + JNU_CHECK_EXCEPTION_RETURN(env, NULL); if (IS_NULL(host)) { JNU_ThrowNullPointerException(env, "host argument"); @@ -199,13 +183,13 @@ address |= (addr[1]<<8) & 0xff00; address |= addr[0]; - ret = (*env)->NewObjectArray(env, 1, ni_iacls, NULL); + ret = (*env)->NewObjectArray(env, 1, ia_class, NULL); if (IS_NULL(ret)) { goto cleanupAndReturn; } - iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); + iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (IS_NULL(iaObj)) { ret = NULL; goto cleanupAndReturn; @@ -229,7 +213,7 @@ addrp++; } - ret = (*env)->NewObjectArray(env, i, ni_iacls, NULL); + ret = (*env)->NewObjectArray(env, i, ia_class, NULL); if (IS_NULL(ret)) { goto cleanupAndReturn; @@ -238,7 +222,7 @@ addrp = (struct in_addr **) hp->h_addr_list; i = 0; while (*addrp != (struct in_addr *) 0) { - jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); + jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (IS_NULL(iaObj)) { ret = NULL; goto cleanupAndReturn;
--- a/src/windows/native/java/net/Inet6AddressImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/java/net/Inet6AddressImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -74,13 +74,6 @@ return JNU_NewStringPlatform (env, hostname); } -static jclass ni_iacls; -static jclass ni_ia4cls; -static jclass ni_ia6cls; -static jmethodID ni_ia4ctrID; -static jmethodID ni_ia6ctrID; -static int initialized = 0; - JNIEXPORT jobjectArray JNICALL Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, jstring host) { @@ -88,30 +81,13 @@ jobjectArray ret = 0; int retLen = 0; jboolean preferIPv6Address; - static jfieldID ia_preferIPv6AddressID; int error=0; struct addrinfo hints, *res, *resNew = NULL; - if (!initialized) { - ni_iacls = (*env)->FindClass(env, "java/net/InetAddress"); - CHECK_NULL_RETURN(ni_iacls, NULL); - ni_iacls = (*env)->NewGlobalRef(env, ni_iacls); - CHECK_NULL_RETURN(ni_iacls, NULL); - ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address"); - CHECK_NULL_RETURN(ni_ia4cls, NULL); - ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls); - CHECK_NULL_RETURN(ni_ia4cls, NULL); - ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address"); - CHECK_NULL_RETURN(ni_ia6cls, NULL); - ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls); - CHECK_NULL_RETURN(ni_ia6cls, NULL); - ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V"); - CHECK_NULL_RETURN(ni_ia4ctrID, NULL); - ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V"); - CHECK_NULL_RETURN(ni_ia6ctrID, NULL); - initialized = 1; - } + initInetAddressIDs(env); + JNU_CHECK_EXCEPTION_RETURN(env, NULL); + if (IS_NULL(host)) { JNU_ThrowNullPointerException(env, "host is null"); return 0; @@ -119,17 +95,6 @@ hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE); CHECK_NULL_RETURN(hostname, NULL); - if (ia_preferIPv6AddressID == NULL) { - jclass c = (*env)->FindClass(env,"java/net/InetAddress"); - if (c) { - ia_preferIPv6AddressID = - (*env)->GetStaticFieldID(env, c, "preferIPv6Address", "Z"); - } - if (ia_preferIPv6AddressID == NULL) { - JNU_ReleaseStringPlatformChars(env, host, hostname); - return NULL; - } - } /* get the address preference */ preferIPv6Address = (*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID); @@ -231,7 +196,7 @@ retLen = i; iterator = resNew; i = 0; - ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL); + ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL); if (IS_NULL(ret)) { /* we may have memory to free at the end of this */ @@ -248,7 +213,7 @@ while (iterator != NULL) { if (iterator->ai_family == AF_INET) { - jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); + jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (IS_NULL(iaObj)) { ret = NULL; goto cleanupAndReturn; @@ -259,7 +224,7 @@ inetIndex ++; } else if (iterator->ai_family == AF_INET6) { jint scope = 0, ret1; - jobject iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID); + jobject iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); if (IS_NULL(iaObj)) { ret = NULL; goto cleanupAndReturn; @@ -349,6 +314,7 @@ if (!error) { ret = (*env)->NewStringUTF(env, host); + CHECK_NULL_RETURN(ret, NULL); } if (ret == NULL) {
--- a/src/windows/native/java/net/NetworkInterface.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/java/net/NetworkInterface.c Fri Nov 11 13:33:15 2016 +0000 @@ -65,13 +65,6 @@ jfieldID ni_nameID; /* NetworkInterface.name */ jfieldID ni_displayNameID; /* NetworkInterface.displayName */ jfieldID ni_childsID; /* NetworkInterface.childs */ -jclass ni_iacls; /* InetAddress */ - -jclass ni_ia4cls; /* Inet4Address */ -jmethodID ni_ia4Ctor; /* Inet4Address() */ - -jclass ni_ia6cls; /* Inet6Address */ -jmethodID ni_ia6ctrID; /* Inet6Address() */ jclass ni_ibcls; /* InterfaceAddress */ jmethodID ni_ibctrID; /* InterfaceAddress() */ @@ -515,26 +508,6 @@ CHECK_NULL(ni_childsID); ni_ctor = (*env)->GetMethodID(env, ni_class, "<init>", "()V"); CHECK_NULL(ni_ctor); - - ni_iacls = (*env)->FindClass(env, "java/net/InetAddress"); - CHECK_NULL(ni_iacls); - ni_iacls = (*env)->NewGlobalRef(env, ni_iacls); - CHECK_NULL(ni_iacls); - - ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address"); - CHECK_NULL(ni_ia4cls); - ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls); - CHECK_NULL(ni_ia4cls); - ni_ia4Ctor = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V"); - CHECK_NULL(ni_ia4Ctor); - - ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address"); - CHECK_NULL(ni_ia6cls); - ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls); - CHECK_NULL(ni_ia6cls); - ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V"); - CHECK_NULL(ni_ia6ctrID); - ni_ibcls = (*env)->FindClass(env, "java/net/InterfaceAddress"); CHECK_NULL(ni_ibcls); ni_ibcls = (*env)->NewGlobalRef(env, ni_ibcls); @@ -546,6 +519,9 @@ ni_ibbroadcastID = (*env)->GetFieldID(env, ni_ibcls, "broadcast", "Ljava/net/Inet4Address;"); CHECK_NULL(ni_ibbroadcastID); ni_ibmaskID = (*env)->GetFieldID(env, ni_ibcls, "maskLength", "S"); + CHECK_NULL(ni_ibmaskID); + + initInetAddressIDs(env); } /* @@ -591,7 +567,7 @@ return NULL; } } - addrArr = (*env)->NewObjectArray(env, netaddrCount, ni_iacls, NULL); + addrArr = (*env)->NewObjectArray(env, netaddrCount, ia_class, NULL); if (addrArr == NULL) { free_netaddr(netaddrP); return NULL; @@ -609,7 +585,7 @@ jobject iaObj, ia2Obj; jobject ibObj = NULL; if (addrs->addr.him.sa_family == AF_INET) { - iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor); + iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (iaObj == NULL) { free_netaddr(netaddrP); return NULL; @@ -624,7 +600,7 @@ return NULL; } (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj); - ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor); + ia2Obj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (ia2Obj == NULL) { free_netaddr(netaddrP); return NULL; @@ -636,7 +612,7 @@ } } else /* AF_INET6 */ { int scope; - iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID); + iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); if (iaObj) { int ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr)); if (ret == JNI_FALSE) {
--- a/src/windows/native/java/net/NetworkInterface.h Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/java/net/NetworkInterface.h Fri Nov 11 13:33:15 2016 +0000 @@ -70,16 +70,6 @@ extern jfieldID ni_displayNameID; /* NetworkInterface.displayName */ extern jfieldID ni_childsID; /* NetworkInterface.childs */ -extern jclass ni_iacls; /* InetAddress */ - -extern jclass ni_ia4cls; /* Inet4Address */ -extern jmethodID ni_ia4Ctor; /* Inet4Address() */ - -extern jclass ni_ia6cls; /* Inet6Address */ -extern jmethodID ni_ia6ctrID; /* Inet6Address() */ -extern jfieldID ni_ia6ipaddressID; -extern jfieldID ni_ia6ipaddressID; - extern jclass ni_ibcls; /* InterfaceAddress */ extern jmethodID ni_ibctrID; /* InterfaceAddress() */ extern jfieldID ni_ibaddressID; /* InterfaceAddress.address */
--- a/src/windows/native/java/net/NetworkInterface_winXP.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/java/net/NetworkInterface_winXP.c Fri Nov 11 13:33:15 2016 +0000 @@ -489,14 +489,20 @@ * Create a NetworkInterface object and populate it */ netifObj = (*env)->NewObject(env, ni_class, ni_ctor); + if (netifObj == NULL) { + return NULL; + } name = (*env)->NewStringUTF(env, ifs->name); + if (name == NULL) { + return NULL; + } if (ifs->dNameIsUnicode) { displayName = (*env)->NewString(env, (PWCHAR)ifs->displayName, (jsize)wcslen ((PWCHAR)ifs->displayName)); } else { displayName = (*env)->NewStringUTF(env, ifs->displayName); } - if (netifObj == NULL || name == NULL || displayName == NULL) { + if (displayName == NULL) { return NULL; } (*env)->SetObjectField(env, netifObj, ni_nameID, name); @@ -513,7 +519,7 @@ } } - addrArr = (*env)->NewObjectArray(env, netaddrCount, ni_iacls, NULL); + addrArr = (*env)->NewObjectArray(env, netaddrCount, ia_class, NULL); if (addrArr == NULL) { return NULL; } @@ -531,7 +537,7 @@ jobject iaObj, ia2Obj; jobject ibObj = NULL; if (addrs->addr.him.sa_family == AF_INET) { - iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor); + iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (iaObj == NULL) { return NULL; } @@ -545,7 +551,7 @@ return NULL; } (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj); - ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor); + ia2Obj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (ia2Obj == NULL) { free_netaddr(netaddrP); return NULL; @@ -556,26 +562,28 @@ (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj); } else /* AF_INET6 */ { int scope; - iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID); - if (iaObj) { - int ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr)); - if (ret == JNI_FALSE) { - return NULL; - } - scope = addrs->addr.him6.sin6_scope_id; - if (scope != 0) { /* zero is default value, no need to set */ - setInet6Address_scopeid(env, iaObj, scope); - setInet6Address_scopeifname(env, iaObj, netifObj); - } - ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID); - if (ibObj == NULL) { - free_netaddr(netaddrP); - return NULL; - } - (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj); - (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask); - (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj); + int ret; + iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); + if (iaObj == NULL) { + return NULL; } + ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr)); + if (ret == JNI_FALSE) { + return NULL; + } + scope = addrs->addr.him6.sin6_scope_id; + if (scope != 0) { /* zero is default value, no need to set */ + setInet6Address_scopeid(env, iaObj, scope); + setInet6Address_scopeifname(env, iaObj, netifObj); + } + ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID); + if (ibObj == NULL) { + free_netaddr(netaddrP); + return NULL; + } + (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj); + (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask); + (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj); } (*env)->SetObjectArrayElement(env, addrArr, addr_index, iaObj); addrs = addrs->next;
--- a/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -838,6 +838,7 @@ } if (IS_NULL(addressObj)) { JNU_ThrowNullPointerException(env, "Null address in peek()"); + return -1; } else { address = getInetAddress_addr(env, addressObj); /* We only handle IPv4 for now. Will support IPv6 once its in the os */ @@ -1150,11 +1151,23 @@ } if (n == -1) { JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed"); + if (packetBufferLen > MAX_BUFFER_LEN) { + free(fullPacket); + } + return -1; } else if (n == -2) { JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException", "operation interrupted"); + if (packetBufferLen > MAX_BUFFER_LEN) { + free(fullPacket); + } + return -1; } else if (n < 0) { NET_ThrowCurrent(env, "Datagram receive failed"); + if (packetBufferLen > MAX_BUFFER_LEN) { + free(fullPacket); + } + return -1; } else { jobject packetAddress; @@ -1914,7 +1927,7 @@ default : JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket option not supported by PlainDatagramSocketImp"); - break; + return; } @@ -2357,6 +2370,7 @@ if (NET_SetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&ittl, sizeof (ittl)) < 0) { NET_ThrowCurrent(env, "set IP_MULTICAST_TTL failed"); + return; } } @@ -2550,6 +2564,9 @@ } else { ifindex = getIndexFromIf (env, niObj); if (ifindex == -1) { + if ((*env)->ExceptionOccurred(env)) { + return; + } NET_ThrowCurrent(env, "get ifindex failed"); return; }
--- a/src/windows/native/java/net/TwoStacksPlainSocketImpl.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/java/net/TwoStacksPlainSocketImpl.c Fri Nov 11 13:33:15 2016 +0000 @@ -109,7 +109,7 @@ psi_portID = (*env)->GetFieldID(env, cls, "port", "I"); CHECK_NULL(psi_portID); psi_lastfdID = (*env)->GetFieldID(env, cls, "lastfd", "I"); - CHECK_NULL(psi_portID); + CHECK_NULL(psi_lastfdID); psi_localportID = (*env)->GetFieldID(env, cls, "localport", "I"); CHECK_NULL(psi_localportID); psi_timeoutID = (*env)->GetFieldID(env, cls, "timeout", "I"); @@ -154,17 +154,17 @@ fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID); if (IS_NULL(fd1Obj)) { + (*env)->SetIntField(env, fdObj, IO_fd_fdID, -1); + NET_SocketClose(fd); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "null fd1 object"); - (*env)->SetIntField(env, fdObj, IO_fd_fdID, -1); - NET_SocketClose(fd); return; } fd1 = socket(AF_INET6, (stream ? SOCK_STREAM: SOCK_DGRAM), 0); if (fd1 == -1) { - NET_ThrowCurrent(env, "create"); (*env)->SetIntField(env, fdObj, IO_fd_fdID, -1); NET_SocketClose(fd); + NET_ThrowCurrent(env, "create"); return; } else { /* Set socket attribute so it is not passed to any child process */ @@ -911,6 +911,7 @@ isRcvTimeoutSupported = JNI_FALSE; } else { NET_ThrowCurrent(env, "setsockopt SO_RCVTIMEO"); + return; } } if (fd1 != -1) {
--- a/src/windows/native/java/nio/MappedByteBuffer.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/java/nio/MappedByteBuffer.c Fri Nov 11 13:33:15 2016 +0000 @@ -83,9 +83,9 @@ HANDLE h; if (handle_fdID == NULL) { jclass clazz = (*env)->FindClass(env, "java/io/FileDescriptor"); - if (clazz == NULL) - return; // exception thrown + CHECK_NULL(clazz); //exception thrown handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J"); + CHECK_NULL(handle_fdID); } h = jlong_to_ptr((*env)->GetLongField(env, fdo, handle_fdID)); result = FlushFileBuffers(h);
--- a/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.cpp Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.cpp Fri Nov 11 13:33:15 2016 +0000 @@ -128,7 +128,7 @@ return; } hDC = comp->GetDCFromComponent(); - if (hDC != NULL) { + if (hDC != NULL && wsdo->device != NULL) { ::SelectObject(hDC, nullbrush); ::SelectObject(hDC, nullpen); ::SelectClipRgn(hDC, (HRGN) NULL);
--- a/src/windows/native/sun/nio/ch/IOUtil.c Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/sun/nio/ch/IOUtil.c Fri Nov 11 13:33:15 2016 +0000 @@ -33,6 +33,7 @@ #include "nio.h" #include "nio_util.h" +#include "net_util.h" #include "sun_nio_ch_IOUtil.h" /* field id for jlong 'handle' in java.io.FileDescriptor used for file fds */ @@ -55,6 +56,7 @@ CHECK_NULL(clazz = (*env)->FindClass(env, "java/io/FileDescriptor")); CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I")); CHECK_NULL(handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J")); + initInetAddressIDs(env); } /**************************************************************
--- a/src/windows/native/sun/windows/awt_Component.cpp Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/sun/windows/awt_Component.cpp Fri Nov 11 13:33:15 2016 +0000 @@ -256,6 +256,8 @@ AwtComponent::BuildPrimaryDynamicTable(); sm_PrimaryDynamicTableBuilt = TRUE; } + + deadKeyActive = FALSE; } AwtComponent::~AwtComponent() @@ -2936,6 +2938,7 @@ {0x037A, java_awt_event_KeyEvent_VK_DEAD_IOTA}, // ASCII ??? {0x309B, java_awt_event_KeyEvent_VK_DEAD_VOICED_SOUND}, {0x309C, java_awt_event_KeyEvent_VK_DEAD_SEMIVOICED_SOUND}, + {0x0004, java_awt_event_KeyEvent_VK_COMPOSE}, {0,0} }; @@ -3428,8 +3431,9 @@ AwtToolkit::GetKeyboardState(keyboardState); // apply modifiers to keyboard state if necessary + BOOL shiftIsDown = FALSE; if (modifiers) { - BOOL shiftIsDown = modifiers & java_awt_event_InputEvent_SHIFT_DOWN_MASK; + shiftIsDown = modifiers & java_awt_event_InputEvent_SHIFT_DOWN_MASK; BOOL altIsDown = modifiers & java_awt_event_InputEvent_ALT_DOWN_MASK; BOOL ctrlIsDown = modifiers & java_awt_event_InputEvent_CTRL_DOWN_MASK; @@ -3501,18 +3505,27 @@ } // ctrlIsDown } // modifiers - // instead of creating our own conversion tables, I'll let Win32 - // convert the character for me. WORD wChar[2]; - UINT scancode = ::MapVirtualKey(wkey, 0); - int converted = ::ToUnicodeEx(wkey, scancode, keyboardState, - wChar, 2, 0, GetKeyboardLayout()); + int converted = 1; + UINT ch = ::MapVirtualKey(wkey, 2); + if (ch & 0x80000000) { + // Dead key which is handled as a normal key + isDeadKey = deadKeyActive = TRUE; + } else if (deadKeyActive) { + // We cannot use ::ToUnicodeEx if dead key is active because this will + // break dead key function + wChar[0] = shiftIsDown ? ch : tolower(ch); + } else { + UINT scancode = ::MapVirtualKey(wkey, 0); + converted = ::ToUnicodeEx(wkey, scancode, keyboardState, + wChar, 2, 0, GetKeyboardLayout()); + } UINT translation; BOOL deadKeyFlag = (converted == 2); // Dead Key - if (converted < 0) { + if (converted < 0 || isDeadKey) { translation = java_awt_event_KeyEvent_CHAR_UNDEFINED; } else // No translation available -- try known conversions or else punt. @@ -3666,6 +3679,8 @@ MsgRouting AwtComponent::WmChar(UINT character, UINT repCnt, UINT flags, BOOL system) { + deadKeyActive = FALSE; + // Will only get WmChar messages with DBCS if we create them for // an Edit class in the WmForwardChar method. These synthesized // DBCS chars are ok to pass on directly to the default window
--- a/src/windows/native/sun/windows/awt_Component.h Tue Oct 25 08:40:09 2016 -0700 +++ b/src/windows/native/sun/windows/awt_Component.h Fri Nov 11 13:33:15 2016 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -820,6 +820,8 @@ // 6524352: support finer-resolution int m_wheelRotationAmount; + BOOL deadKeyActive; + /* * The association list of children's IDs and corresponding components. * Some components like Choice or List are required their sizes while
--- a/test/java/awt/InputMethods/DiacriticsTest/DiacriticsTest.html Tue Oct 25 08:40:09 2016 -0700 +++ b/test/java/awt/InputMethods/DiacriticsTest/DiacriticsTest.html Fri Nov 11 13:33:15 2016 +0000 @@ -1,5 +1,5 @@ <!-- -Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. +Copyright (c) 2013, 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 @@ -31,6 +31,8 @@ Test run requires the following keyboard layouts to be installed: Linux OS: English (US, alternative international) Windows OS: Hungarian +A keyboard layout having compose function or compose-like key. Programmer +Dvorak (http://www.kaufmann.no/roland/dvorak/) is suggested to use. To test JDK-8000423 fix (Linux only!): please switch to US alternative international layout and try to type diacritics @@ -40,6 +42,12 @@ please switch to Hungarian keyboard layout and try to type diacritics (Ctrl+Alt+2 e; Ctrl+Alt+2 E) +To test JDK-8139189 fix: +please switch to Programmer Dvorak keyboard layout try to type diacritics +using compose combinations (Compose+z+d, Compose+z+Shift+d). The Compose key +in Programmer Dvorak layout is OEM102 the key which is located between +Left Shift and Z keys on the standard 102-key keyboard. + If you can do that then the test is passed; otherwise failed. </body> </html>
--- a/test/java/awt/event/KeyEvent/KeyChar/KeyCharTest.java Tue Oct 25 08:40:09 2016 -0700 +++ b/test/java/awt/event/KeyEvent/KeyChar/KeyCharTest.java Fri Nov 11 13:33:15 2016 +0000 @@ -32,7 +32,7 @@ /* * @test - * @bug 8022401 + * @bug 8022401 8160623 * @summary Wrong key char * @author Alexandr Scherbatiy * @run main KeyCharTest
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/crypto/CryptoPermission/TestUnlimited.java Fri Nov 11 13:33:15 2016 +0000 @@ -0,0 +1,96 @@ +/* + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 8157561 + * @summary Ship the unlimited policy files in JDK Updates + * @run main/othervm TestUnlimited "" exception + * @run main/othervm TestUnlimited limited fail + * @run main/othervm TestUnlimited unlimited pass + * @run main/othervm TestUnlimited unlimited/ pass + * @run main/othervm TestUnlimited NosuchDir exception + * @run main/othervm TestUnlimited . exception + * @run main/othervm TestUnlimited /tmp/unlimited exception + * @run main/othervm TestUnlimited ../policy/unlimited exception + * @run main/othervm TestUnlimited ./unlimited exception + * @run main/othervm TestUnlimited /unlimited exception + */ +import javax.crypto.*; +import java.security.Security; + +public class TestUnlimited { + + public static void main(String[] args) throws Exception { + /* + * Override the Security property to allow for unlimited policy. + * Would need appropriate permissions if Security Manager were + * active. + */ + if (args.length != 2) { + throw new Exception("Two args required"); + } + + boolean expected = args[1].equals("pass"); + boolean exception = args[1].equals("exception"); + boolean result = false; + + System.out.println("Testing: " + args[0]); + + if (args[0].equals("\"\"")) { + Security.setProperty("crypto.policy", ""); + } else { + Security.setProperty("crypto.policy", args[0]); + } + + /* + * Use the AES as the test Cipher + * If there is an error initializing, we will never get past here. + */ + try { + int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES"); + System.out.println("max AES key len:" + maxKeyLen); + if (maxKeyLen > 128) { + System.out.println("Unlimited policy is active"); + result = true; + } else { + System.out.println("Unlimited policy is NOT active"); + result = false; + } + } catch (Throwable e) { + if (!exception) { + throw new Exception(); + } + } + + System.out.println( + "Expected:\t" + expected + "\nResult:\t\t" + result); + if (expected != result) { + throw new Exception(); + } + + System.out.println("DONE!"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/jaxp/transform/8167179/NamespacePrefixTest.java Fri Nov 11 13:33:15 2016 +0000 @@ -0,0 +1,188 @@ +/* + * 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. + */ + +import java.io.StringReader; +import java.io.StringWriter; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +import javax.xml.transform.Source; +import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.testng.annotations.Test; +import static org.testng.Assert.assertTrue; + +/* + * @test + * @bug 8167179 + * @run testng/othervm NamespacePrefixTest + * @summary This class tests the generation of namespace prefixes + */ +public class NamespacePrefixTest { + + @Test + public void testReuseTemplates() throws Exception { + final TransformerFactory tf = TransformerFactory.newInstance(); + final Source xslsrc = new StreamSource(new StringReader(XSL)); + final Templates tmpl = tf.newTemplates(xslsrc); + for (int i = 0; i < TRANSF_COUNT; i++) { + checkResult(doTransformation(tmpl.newTransformer())); + } + } + + @Test + public void testReuseTransformer() throws Exception { + final TransformerFactory tf = TransformerFactory.newInstance(); + final Source xslsrc = new StreamSource(new StringReader(XSL)); + final Transformer t = tf.newTransformer(xslsrc); + for (int i = 0; i < TRANSF_COUNT; i++) { + checkResult(doTransformation(t)); + } + } + + @Test + public void testConcurrentTransformations() throws Exception { + final TransformerFactory tf = TransformerFactory.newInstance(); + final Source xslsrc = new StreamSource(new StringReader(XSL)); + final Templates tmpl = tf.newTemplates(xslsrc); + concurrentTestPassed.set(true); + + // Execute multiple TestWorker tasks + for (int id = 0; id < THREADS_COUNT; id++) { + EXECUTOR.execute(new TransformerThread(tmpl.newTransformer(), id)); + } + // Initiate shutdown of previously submitted task + EXECUTOR.shutdown(); + // Wait for termination of submitted tasks + if (!EXECUTOR.awaitTermination(THREADS_COUNT, TimeUnit.SECONDS)) { + // If not all tasks terminates during the time out force them to shutdown + EXECUTOR.shutdownNow(); + } + // Check if all transformation threads generated the correct namespace prefix + assertTrue(concurrentTestPassed.get()); + } + + // Do one transformation with the provided transformer + private static String doTransformation(Transformer t) throws Exception { + StringWriter resWriter = new StringWriter(); + Source xmlSrc = new StreamSource(new StringReader(XML)); + t.transform(xmlSrc, new StreamResult(resWriter)); + return resWriter.toString(); + } + + // Check if the transformation result string contains the + // element with the exact namespace prefix generated. + private static void checkResult(String result) { + // Check prefix of 'Element2' element, it should always be the same + assertTrue(result.contains(EXPECTED_CONTENT)); + } + + // Check if the transformation result string contains the element with + // the exact namespace prefix generated by current thread. + // If the expected prefix is not found and there was no failures observed by + // other test threads then mark concurrent test as failed. + private static void checkThreadResult(String result, int id) { + boolean res = result.contains(EXPECTED_CONTENT); + System.out.printf("%d: transformation result: %s%n", id, res ? "Pass" : "Fail"); + if (!res) { + System.out.printf("%d result:%s%n", id, result); + } + concurrentTestPassed.compareAndSet(true, res); + } + + // TransformerThread task that does the transformation similar + // to testReuseTransformer test method + private class TransformerThread implements Runnable { + + private final Transformer transformer; + private final int id; + + TransformerThread(Transformer transformer, int id) { + this.transformer = transformer; + this.id = id; + } + + @Override + public void run() { + try { + System.out.printf("%d: waiting for barrier%n", id); + //Synchronize startup of all tasks + BARRIER.await(); + System.out.printf("%d: starting transformation%n", id); + checkThreadResult(doTransformation(transformer), id); + } catch (Exception ex) { + throw new RuntimeException("TransformerThread " + id + " failed", ex); + } + } + } + + // Number of subsequent transformations + private static final int TRANSF_COUNT = 10; + + // Number of transformer threads running concurently + private static final int THREADS_COUNT = 10; + + // Variable for storing the concurrent transformation test result. It is + // updated by transformer threads + private static final AtomicBoolean concurrentTestPassed = new AtomicBoolean(true); + + // Cyclic barrier for threads startup synchronization + private static final CyclicBarrier BARRIER = new CyclicBarrier(THREADS_COUNT); + + // Thread pool + private static final ExecutorService EXECUTOR = Executors.newCachedThreadPool(); + + // XSL that transforms XML and produces unique namespace prefixes for each element + private final static String XSL = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n" + + " <xsl:template match=\"node()|@*\" priority=\"1\">\n" + + " <xsl:copy>\n" + + " <xsl:apply-templates select=\"node()|@*\"/>\n" + + " </xsl:copy>\n" + + " </xsl:template>\n" + + " <xsl:template match=\"*\" priority=\"2\">\n" + + " <xsl:element name=\"{name()}\" namespace=\"{namespace-uri()}\">\n" + + " <xsl:apply-templates select=\"node()|@*\"/>\n" + + " </xsl:element>\n" + + " </xsl:template>\n" + + "</xsl:stylesheet>"; + + // Simple XML content with root and two child elements + private final static String XML = "<TestRoot xmlns=\"test.xmlns\">\n" + + " <Element1 xmlns=\"test.xmlns\">\n" + + " </Element1>\n" + + " <Element2 xmlns=\"test.xmlns\">\n" + + " </Element2>\n" + + "</TestRoot>"; + + // With thread local namespace prefix index each transformation result should + // be the same and contain the same prefix for Element2 + private final static String EXPECTED_CONTENT = "</ns2:Element2>"; + +}
--- a/test/sun/security/krb5/canonicalize/Test.java Tue Oct 25 08:40:09 2016 -0700 +++ b/test/sun/security/krb5/canonicalize/Test.java Fri Nov 11 13:33:15 2016 +0000 @@ -22,7 +22,7 @@ */ /* * @test - * @bug 6682516 + * @bug 6682516 8149521 * @summary SPNEGO_HTTP_AUTH/WWW_KRB and SPNEGO_HTTP_AUTH/WWW_SPNEGO failed on all non-windows platforms * @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Djava.security.krb5.conf=krb5.conf Test */ @@ -43,9 +43,11 @@ check("c1", "c1.this.domain"); check("c1.this", "c1.this.domain"); check("c1.this.domain", "c1.this.domain"); + check("c1.this.domain.", "c1.this.domain"); // canonicalized name goes IP, reject check("c2", "c2"); + check("c2.", "c2"); // canonicalized name goes strange, reject check("c3", "c3");
--- a/test/sun/security/tools/jarsigner/warnings/Test.java Tue Oct 25 08:40:09 2016 -0700 +++ b/test/sun/security/tools/jarsigner/warnings/Test.java Fri Nov 11 13:33:15 2016 +0000 @@ -22,6 +22,11 @@ */ import jdk.testlibrary.OutputAnalyzer; +import jdk.testlibrary.ProcessTools; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * Base class. @@ -175,4 +180,21 @@ } analyzer.shouldContain(JAR_SIGNED); } + + protected OutputAnalyzer keytool(String... cmd) throws Throwable { + return tool(KEYTOOL, cmd); + } + + protected OutputAnalyzer jarsigner(String... cmd) throws Throwable { + return tool(JARSIGNER, cmd); + } + + private OutputAnalyzer tool(String tool, String... args) throws Throwable { + List<String> cmd = new ArrayList<>(); + cmd.add(tool); + cmd.add("-J-Duser.language=en"); + cmd.add("-J-Duser.country=US"); + cmd.addAll(Arrays.asList(args)); + return ProcessTools.executeCommand(cmd.toArray(new String[cmd.size()])); + } }