diff --git a/.hgtags b/.hgtags index 9769641d3efcf25f3422464f3789e06b619dbd9e..aca2b6790dd233b2580777e2a7d321cb6bf1d595 100644 --- a/.hgtags +++ b/.hgtags @@ -289,3 +289,4 @@ bf4acb74e4a82d6126ad7a82bd8c52bdcce4bc8d jdk8u20-b14 d723d05cd17afd5c4dd4293bcba83fef44a3c0bb jdk8u20-b16 31433e5da5bcfd107381f281058dc80377f04d23 jdk8u20-b17 266302e9c31172984493404d5b223979315b59ac jdk8u20-b18 +38548d32c91cfa57b1d31eec0a5e79c936e86f11 jdk8u20-b19 diff --git a/make/CompileJavaClasses.gmk b/make/CompileJavaClasses.gmk index e4c7b3aea1c8f4526d3166db526d43c50064bfee..d7d565cf017e707a49d6d3e612b21499e7c64cdb 100644 --- a/make/CompileJavaClasses.gmk +++ b/make/CompileJavaClasses.gmk @@ -52,8 +52,9 @@ ifdef OPENJDK endif ifndef OPENJDK - # There exists two versions of this file... + # There exists two versions of these files... EXFILES := $(JDK_TOPDIR)/src/share/classes/javax/crypto/JarVerifier.java + EXFILES += $(JDK_TOPDIR)/src/share/classes/sun/management/ExtendedPlatformComponent.java ifeq ($(OPENJDK_TARGET_OS), windows) # This gets built on unix platforms implicitly in the old build even though diff --git a/src/share/classes/java/lang/management/ManagementFactory.java b/src/share/classes/java/lang/management/ManagementFactory.java index 0c7297abe956d00027eab965baf466dc0bf09c27..c444713549667307c354da0133364609231999ee 100644 --- a/src/share/classes/java/lang/management/ManagementFactory.java +++ b/src/share/classes/java/lang/management/ManagementFactory.java @@ -52,6 +52,7 @@ import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import javax.management.JMX; import sun.management.ManagementFactoryHelper; +import sun.management.ExtendedPlatformComponent; /** * The {@code ManagementFactory} class is a factory class for getting @@ -489,6 +490,12 @@ public class ManagementFactory { for (Map.Entry e : dynmbeans.entrySet()) { addDynamicMBean(platformMBeanServer, e.getValue(), e.getKey()); } + for (final PlatformManagedObject o : + ExtendedPlatformComponent.getMXBeans()) { + if (!platformMBeanServer.isRegistered(o.getObjectName())) { + addMXBean(platformMBeanServer, o); + } + } } return platformMBeanServer; } @@ -655,9 +662,14 @@ public class ManagementFactory { public static T getPlatformMXBean(Class mxbeanInterface) { PlatformComponent pc = PlatformComponent.getPlatformComponent(mxbeanInterface); - if (pc == null) + if (pc == null) { + T mbean = ExtendedPlatformComponent.getMXBean(mxbeanInterface); + if (mbean != null) { + return mbean; + } throw new IllegalArgumentException(mxbeanInterface.getName() + " is not a platform management interface"); + } if (!pc.isSingleton()) throw new IllegalArgumentException(mxbeanInterface.getName() + " can have zero or more than one instances"); @@ -690,9 +702,14 @@ public class ManagementFactory { public static List getPlatformMXBeans(Class mxbeanInterface) { PlatformComponent pc = PlatformComponent.getPlatformComponent(mxbeanInterface); - if (pc == null) + if (pc == null) { + T mbean = ExtendedPlatformComponent.getMXBean(mxbeanInterface); + if (mbean != null) { + return Collections.singletonList(mbean); + } throw new IllegalArgumentException(mxbeanInterface.getName() + " is not a platform management interface"); + } return Collections.unmodifiableList(pc.getMXBeans(mxbeanInterface)); } @@ -737,9 +754,17 @@ public class ManagementFactory { throws java.io.IOException { PlatformComponent pc = PlatformComponent.getPlatformComponent(mxbeanInterface); - if (pc == null) + if (pc == null) { + T mbean = ExtendedPlatformComponent.getMXBean(mxbeanInterface); + if (mbean != null) { + ObjectName on = mbean.getObjectName(); + return ManagementFactory.newPlatformMXBeanProxy(connection, + on.getCanonicalName(), + mxbeanInterface); + } throw new IllegalArgumentException(mxbeanInterface.getName() + " is not a platform management interface"); + } if (!pc.isSingleton()) throw new IllegalArgumentException(mxbeanInterface.getName() + " can have zero or more than one instances"); @@ -781,6 +806,13 @@ public class ManagementFactory { { PlatformComponent pc = PlatformComponent.getPlatformComponent(mxbeanInterface); if (pc == null) { + T mbean = ExtendedPlatformComponent.getMXBean(mxbeanInterface); + if (mbean != null) { + ObjectName on = mbean.getObjectName(); + T proxy = ManagementFactory.newPlatformMXBeanProxy(connection, + on.getCanonicalName(), mxbeanInterface); + return Collections.singletonList(proxy); + } throw new IllegalArgumentException(mxbeanInterface.getName() + " is not a platform management interface"); } diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java b/src/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java index 7acfff532f5185523554bc3d3fe6c49a3256d3b4..8dec6eda0bda621cbcec3c0d6c3f8d09fcb5a7df 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java @@ -550,6 +550,7 @@ public class InsnList { } // this class is not generified because it will create bridges + @SuppressWarnings("rawtypes") private final class InsnListIterator implements ListIterator { AbstractInsnNode next; diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/tree/MethodNode.java b/src/share/classes/jdk/internal/org/objectweb/asm/tree/MethodNode.java index bb01f7a7a3df76b5a0a763d3fbc17b9f74b9671e..1561442761a1be51d9119a043c9407bba69c4c6d 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/tree/MethodNode.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/tree/MethodNode.java @@ -399,6 +399,7 @@ public class MethodNode extends MethodVisitor { } @Override + @SuppressWarnings("unchecked") public AnnotationVisitor visitParameterAnnotation(final int parameter, final String desc, final boolean visible) { AnnotationNode an = new AnnotationNode(desc); diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Analyzer.java b/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Analyzer.java index 8f987532efdfb00d92a2472b458041e82c992473..b8d6fdaa1e0528b1dfd1e3d052dd72ac84e5424f 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Analyzer.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Analyzer.java @@ -131,6 +131,7 @@ public class Analyzer implements Opcodes { * @throws AnalyzerException * if a problem occurs during the analysis. */ + @SuppressWarnings("unchecked") public Frame[] analyze(final String owner, final MethodNode m) throws AnalyzerException { if ((m.access & (ACC_ABSTRACT | ACC_NATIVE)) != 0) { diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Frame.java b/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Frame.java index cbb5f86f53469a3b0e9108bad0404d800b4c5593..4ba309d0cbf84453d1f648aa00c00340bece9c74 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Frame.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Frame.java @@ -112,6 +112,7 @@ public class Frame { * @param nStack * the maximum stack size of the frame. */ + @SuppressWarnings("unchecked") public Frame(final int nLocals, final int nStack) { this.values = (V[]) new Value[nLocals + nStack]; this.locals = nLocals; diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/version.txt b/src/share/classes/jdk/internal/org/objectweb/asm/version.txt index b1d916092e596f0b2dc2eedcc1829a2ee9db99e8..d93a6c4b4fdeef658199f57c498d9e8a9275b061 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/version.txt +++ b/src/share/classes/jdk/internal/org/objectweb/asm/version.txt @@ -1,12 +1,12 @@ Path: . -Working Copy Root Path: /hudson/jobs/objectweb-pull/workspace/asm-svn-2014-05-27 +Working Copy Root Path: /hudson/jobs/objectweb-pull/workspace/asm-svn-2014-06-19 URL: file:///svnroot/asm/trunk/asm Repository Root: file:///svnroot/asm Repository UUID: 271bd773-ee82-43a6-9b2b-1890ed8ce7f9 -Revision: 1748 +Revision: 1750 Node Kind: directory Schedule: normal -Last Changed Author: ebruneton -Last Changed Rev: 1747 -Last Changed Date: 2014-05-24 10:22:13 +0200 (Sat, 24 May 2014) +Last Changed Author: forax +Last Changed Rev: 1750 +Last Changed Date: 2014-06-06 00:31:02 +0200 (Fri, 06 Jun 2014) diff --git a/src/share/classes/jdk/net/Sockets.java b/src/share/classes/jdk/net/Sockets.java index ef75631a0c83ef436aca3e24dae361331a451bd7..2b31a1d5727eedd8f1a5888a9f4bce2044c181eb 100644 --- a/src/share/classes/jdk/net/Sockets.java +++ b/src/share/classes/jdk/net/Sockets.java @@ -119,6 +119,8 @@ public class Sockets { Throwable t = ((InvocationTargetException)e).getTargetException(); if (t instanceof IOException) { throw (IOException)t; + } else if (t instanceof RuntimeException) { + throw (RuntimeException)t; } } throw new RuntimeException(e); @@ -135,6 +137,8 @@ public class Sockets { Throwable t = ((InvocationTargetException)e).getTargetException(); if (t instanceof IOException) { throw (IOException)t; + } else if (t instanceof RuntimeException) { + throw (RuntimeException)t; } } throw new RuntimeException(e); diff --git a/src/share/classes/sun/awt/shell/ShellFolder.java b/src/share/classes/sun/awt/shell/ShellFolder.java index 209974ed948869eed5ed4bd1c19d64758928b0f2..f8ca809728f9558d6c19bc618df8d4edee04cdfe 100644 --- a/src/share/classes/sun/awt/shell/ShellFolder.java +++ b/src/share/classes/sun/awt/shell/ShellFolder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,8 +33,6 @@ import java.io.FileNotFoundException; import java.util.*; import java.util.concurrent.Callable; -import sun.reflect.misc.ReflectUtil; - /** * @author Michael Martak * @since 1.4 @@ -201,16 +199,19 @@ public abstract class ShellFolder extends File { // Static - private static ShellFolderManager shellFolderManager; + private static final ShellFolderManager shellFolderManager; - private static Invoker invoker; + private static final Invoker invoker; static { String managerClassName = (String)Toolkit.getDefaultToolkit(). getDesktopProperty("Shell.shellFolderManager"); Class managerClass = null; try { - managerClass = ReflectUtil.forName(managerClassName); + managerClass = Class.forName(managerClassName, false, null); + if (!ShellFolderManager.class.isAssignableFrom(managerClass)) { + managerClass = null; + } // swallow the exceptions below and use default shell folder } catch(ClassNotFoundException e) { } catch(NullPointerException e) { diff --git a/src/share/classes/sun/management/ExtendedPlatformComponent.java b/src/share/classes/sun/management/ExtendedPlatformComponent.java new file mode 100644 index 0000000000000000000000000000000000000000..ff33ff9b52e5b360c8dfa88d9ae78efa260e6348 --- /dev/null +++ b/src/share/classes/sun/management/ExtendedPlatformComponent.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2014, 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.management; + +import java.util.Collections; +import java.util.List; +import java.lang.management.PlatformManagedObject; + +/** + * Class to allow for an extended set of platform MXBeans + */ +public final class ExtendedPlatformComponent { + private ExtendedPlatformComponent() {} // Don't create any instances + + /** + * Get the extended set of platform MXBeans that should be registered in the + * platform MBeanServer, or an empty list if there are no such MXBeans. + */ + public static List getMXBeans() { + return Collections.emptyList(); + } + + /** + * Returns the extended platform MXBean implementing the given + * mxbeanInterface, or null if there is no such MXBean. + */ + public static + T getMXBean(Class mxbeanInterface) { + return null; + } +} diff --git a/src/windows/native/java/io/WinNTFileSystem_md.c b/src/windows/native/java/io/WinNTFileSystem_md.c index 3c8b821e02774071327fcc87694cd646bef6d617..2a0d477a7d2bc999a6bcbe50eee43ce920a8534d 100644 --- a/src/windows/native/java/io/WinNTFileSystem_md.c +++ b/src/windows/native/java/io/WinNTFileSystem_md.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2014, 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 @@ -83,7 +83,7 @@ extern int wcanonicalizeWithPrefix(const WCHAR *canonicalPrefix, const WCHAR *pa * Retrieves the fully resolved (final) path for the given path or NULL * if the function fails. */ -static WCHAR* getFinalPath(const WCHAR *path) +static WCHAR* getFinalPath(JNIEnv *env, const WCHAR *path) { HANDLE h; WCHAR *result; @@ -119,6 +119,7 @@ static WCHAR* getFinalPath(const WCHAR *path) len = (*GetFinalPathNameByHandle_func)(h, result, len, 0); } else { len = 0; + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); } } @@ -139,6 +140,7 @@ static WCHAR* getFinalPath(const WCHAR *path) /* copy result without prefix into new buffer */ WCHAR *tmp = (WCHAR*)malloc(resultLen * sizeof(WCHAR)); if (tmp == NULL) { + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); len = 0; } else { WCHAR *p = result; @@ -162,6 +164,8 @@ static WCHAR* getFinalPath(const WCHAR *path) free(result); result = NULL; } + } else { + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); } error = GetLastError(); @@ -255,6 +259,8 @@ Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this, rv = (*env)->NewString(env, cp, (jsize)wcslen(cp)); } free(cp); + } else { + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); } } else if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) { @@ -287,6 +293,8 @@ Java_java_io_WinNTFileSystem_canonicalizeWithPrefix0(JNIEnv *env, jobject this, rv = (*env)->NewString(env, cp, (jsize)wcslen(cp)); } free(cp); + } else { + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); } } else if (wcanonicalizeWithPrefix(canonicalPrefix, @@ -434,7 +442,7 @@ Java_java_io_WinNTFileSystem_setPermission(JNIEnv *env, jobject this, if ((a != INVALID_FILE_ATTRIBUTES) && ((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0)) { - WCHAR *fp = getFinalPath(pathbuf); + WCHAR *fp = getFinalPath(env, pathbuf); if (fp == NULL) { a = INVALID_FILE_ATTRIBUTES; } else { @@ -624,6 +632,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) if (search_path == 0) { free (pathbuf); errno = ENOMEM; + JNU_ThrowOutOfMemoryError(env, "native memory allocation faiuled"); return NULL; } wcscpy(search_path, pathbuf); @@ -801,7 +810,7 @@ Java_java_io_WinNTFileSystem_setReadOnly(JNIEnv *env, jobject this, if ((a != INVALID_FILE_ATTRIBUTES) && ((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0)) { - WCHAR *fp = getFinalPath(pathbuf); + WCHAR *fp = getFinalPath(env, pathbuf); if (fp == NULL) { a = INVALID_FILE_ATTRIBUTES; } else { diff --git a/src/windows/native/java/io/io_util_md.c b/src/windows/native/java/io/io_util_md.c index 33a70183fff8a261ce0a5d2d2ecd42961abf667c..8f777a0a41220d7eccc68dc99f8689aee78daf42 100644 --- a/src/windows/native/java/io/io_util_md.c +++ b/src/windows/native/java/io/io_util_md.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2014, 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 @@ -191,9 +191,9 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) { int dirlen = currentDirLength(ps, pathlen); if (dirlen + pathlen + 1 > max_path - 1) { pathbuf = prefixAbpath(ps, pathlen, dirlen + pathlen); - if( pathbuf == NULL) { - JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); - return NULL; + if (pathbuf == NULL) { + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); + return NULL; } } else { pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR)); @@ -216,12 +216,17 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) { return NULL; } else { pathbuf = (WCHAR*)malloc(sizeof(WCHAR)); - pathbuf[0] = L'\0'; + if (pathbuf != NULL) { + pathbuf[0] = L'\0'; + } else { + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); + return NULL; + } } } if (pathbuf == 0) { if (!(*env)->ExceptionCheck(env)) { - JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); } return NULL; } diff --git a/src/windows/native/java/lang/ProcessEnvironment_md.c b/src/windows/native/java/lang/ProcessEnvironment_md.c index e64d30b74af58a7faeb7aaae190f7cd3a95478e3..69bd50b28aa005056a9c5e015369f881ababfde2 100644 --- a/src/windows/native/java/lang/ProcessEnvironment_md.c +++ b/src/windows/native/java/lang/ProcessEnvironment_md.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014 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 @@ -32,10 +32,17 @@ static jstring environmentBlock9x(JNIEnv *env) { int i; - jmethodID String_init_ID = - (*env)->GetMethodID(env, JNU_ClassString(env), "", "([B)V"); + jmethodID String_init_ID; jbyteArray bytes; - jbyte *blockA = (jbyte *) GetEnvironmentStringsA(); + jbyte *blockA; + jclass string_class; + + string_class= JNU_ClassString(env); + CHECK_NULL_RETURN(string_class, NULL); + String_init_ID = + (*env)->GetMethodID(env, string_class, "", "([B)V"); + CHECK_NULL_RETURN(String_init_ID, NULL); + blockA = (jbyte *) GetEnvironmentStringsA(); if (blockA == NULL) { /* Both GetEnvironmentStringsW and GetEnvironmentStringsA * failed. Out of memory is our best guess. */ @@ -49,10 +56,13 @@ environmentBlock9x(JNIEnv *env) while (blockA[i++]) ; - if ((bytes = (*env)->NewByteArray(env, i)) == NULL) return NULL; + if ((bytes = (*env)->NewByteArray(env, i)) == NULL) { + FreeEnvironmentStringsA(blockA); + return NULL; + } (*env)->SetByteArrayRegion(env, bytes, 0, i, blockA); FreeEnvironmentStringsA(blockA); - return (*env)->NewObject(env, JNU_ClassString(env), + return (*env)->NewObject(env, string_class, String_init_ID, bytes); } diff --git a/src/windows/native/java/lang/ProcessImpl_md.c b/src/windows/native/java/lang/ProcessImpl_md.c index 86f403f863addad8e0d90bf68fc2e5ac06ccf6e8..922e5a501d74d743a7fcdd26e35f6423b39c789c 100644 --- a/src/windows/native/java/lang/ProcessImpl_md.c +++ b/src/windows/native/java/lang/ProcessImpl_md.c @@ -359,24 +359,28 @@ Java_java_lang_ProcessImpl_create(JNIEnv *env, jclass ignored, const jchar *penvBlock = (envBlock != NULL) ? (*env)->GetStringChars(env, envBlock, NULL) : NULL; - const jchar *pdir = (dir != NULL) - ? (*env)->GetStringChars(env, dir, NULL) - : NULL; - jlong *handles = (*env)->GetLongArrayElements(env, stdHandles, NULL); - if (handles != NULL) { - ret = processCreate( - env, - pcmd, - penvBlock, - pdir, - handles, - redirectErrorStream); - (*env)->ReleaseLongArrayElements(env, stdHandles, handles, 0); + if (!(*env)->ExceptionCheck(env)) { + const jchar *pdir = (dir != NULL) + ? (*env)->GetStringChars(env, dir, NULL) + : NULL; + if (!(*env)->ExceptionCheck(env)) { + jlong *handles = (*env)->GetLongArrayElements(env, stdHandles, NULL); + if (handles != NULL) { + ret = processCreate( + env, + pcmd, + penvBlock, + pdir, + handles, + redirectErrorStream); + (*env)->ReleaseLongArrayElements(env, stdHandles, handles, 0); + } + if (pdir != NULL) + (*env)->ReleaseStringChars(env, dir, pdir); + } + if (penvBlock != NULL) + (*env)->ReleaseStringChars(env, envBlock, penvBlock); } - if (pdir != NULL) - (*env)->ReleaseStringChars(env, dir, pdir); - if (penvBlock != NULL) - (*env)->ReleaseStringChars(env, envBlock, penvBlock); (*env)->ReleaseStringChars(env, cmd, pcmd); } } @@ -448,7 +452,7 @@ Java_java_lang_ProcessImpl_isProcessAlive(JNIEnv *env, jclass ignored, jlong han JNIEXPORT jboolean JNICALL Java_java_lang_ProcessImpl_closeHandle(JNIEnv *env, jclass ignored, jlong handle) { - return CloseHandle((HANDLE) handle); + return (jboolean) CloseHandle((HANDLE) handle); } /** diff --git a/src/windows/native/java/util/WindowsPreferences.c b/src/windows/native/java/util/WindowsPreferences.c index 3cfd8ce10a881b77636bac34025ec989c5d65f2a..eacfe397f9defc2dd9cafb1ee611fc974fea3616 100644 --- a/src/windows/native/java/util/WindowsPreferences.c +++ b/src/windows/native/java/util/WindowsPreferences.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2014, 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 @@ -24,8 +24,10 @@ */ #include -#include #include +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" #ifdef __cplusplus extern "C" { #endif @@ -37,12 +39,15 @@ extern "C" { int errorCode=-1; jintArray result; str = (*env)->GetByteArrayElements(env, lpSubKey, NULL); + CHECK_NULL_RETURN(str, NULL); errorCode = RegOpenKeyEx((HKEY)hKey, str, 0, securityMask, &handle); (*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0); tmp[0]= (int) handle; tmp[1]= errorCode; result = (*env)->NewIntArray(env,2); - (*env)->SetIntArrayRegion(env, result, 0, 2, tmp); + if (result != NULL) { + (*env)->SetIntArrayRegion(env, result, 0, 2, tmp); + } return result; } @@ -58,8 +63,9 @@ extern "C" { int tmp[3]; DWORD lpdwDisposition; int errorCode; - jintArray result; + jintArray result = NULL; str = (*env)->GetByteArrayElements(env, lpSubKey, NULL); + CHECK_NULL_RETURN(str, NULL); errorCode = RegCreateKeyEx((HKEY)hKey, str, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &handle, &lpdwDisposition); @@ -68,7 +74,9 @@ extern "C" { tmp[1]= errorCode; tmp[2]= lpdwDisposition; result = (*env)->NewIntArray(env,3); - (*env)->SetIntArrayRegion(env, result, 0, 3, tmp); + if (result != NULL) { + (*env)->SetIntArrayRegion(env, result, 0, 3, tmp); + } return result; } @@ -77,6 +85,7 @@ extern "C" { char* str; int result; str = (*env)->GetByteArrayElements(env, lpSubKey, NULL); + CHECK_NULL_RETURN(str, -1); result = RegDeleteKey((HKEY)hKey, str); (*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0); return result; @@ -96,6 +105,7 @@ extern "C" { DWORD valueType; DWORD valueSize; valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL); + CHECK_NULL_RETURN(valueNameStr, NULL); if (RegQueryValueEx((HKEY)hKey, valueNameStr, NULL, &valueType, NULL, &valueSize) != ERROR_SUCCESS) { (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0); @@ -104,18 +114,26 @@ extern "C" { buffer = (char*)malloc(valueSize); - if (RegQueryValueEx((HKEY)hKey, valueNameStr, NULL, &valueType, buffer, - &valueSize) != ERROR_SUCCESS) { - free(buffer); + if (buffer != NULL) { + if (RegQueryValueEx((HKEY)hKey, valueNameStr, NULL, &valueType, buffer, + &valueSize) != ERROR_SUCCESS) { + free(buffer); + (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0); + return NULL; + } + } else { + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0); - return NULL; + return NULL; } if (valueType == REG_SZ) { - result = (*env)->NewByteArray(env, valueSize); - (*env)->SetByteArrayRegion(env, result, 0, valueSize, buffer); + result = (*env)->NewByteArray(env, valueSize); + if (result != NULL) { + (*env)->SetByteArrayRegion(env, result, 0, valueSize, buffer); + } } else { - result = NULL; + result = NULL; } free(buffer); (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0); @@ -135,7 +153,9 @@ extern "C" { if ((valueName == NULL)||(data == NULL)) {return -1;} size = (*env)->GetArrayLength(env, data); dataStr = (*env)->GetByteArrayElements(env, data, NULL); + CHECK_NULL_RETURN(dataStr, -1); valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL); + CHECK_NULL_RETURN(valueNameStr, -1); error_code = RegSetValueEx((HKEY)hKey, valueNameStr, 0, REG_SZ, dataStr, size); (*env)->ReleaseByteArrayElements(env, data, dataStr, 0); @@ -149,6 +169,7 @@ extern "C" { int error_code = -1; if (valueName == NULL) {return -1;} valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL); + CHECK_NULL_RETURN(valueNameStr, -1); error_code = RegDeleteValue((HKEY)hKey, valueNameStr); (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0); return error_code; @@ -156,7 +177,7 @@ extern "C" { JNIEXPORT jintArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegQueryInfoKey (JNIEnv* env, jclass this_class, jint hKey) { - jintArray result; + jintArray result = NULL; int tmp[5]; int valuesNumber = -1; int maxValueNameLength = -1; @@ -173,7 +194,9 @@ extern "C" { tmp[3]= maxSubKeyLength; tmp[4]= maxValueNameLength; result = (*env)->NewIntArray(env,5); - (*env)->SetIntArrayRegion(env, result, 0, 5, tmp); + if (result != NULL) { + (*env)->SetIntArrayRegion(env, result, 0, 5, tmp); + } return result; } @@ -183,13 +206,19 @@ extern "C" { jbyteArray result; char* buffer = NULL; buffer = (char*)malloc(maxKeyLength); + if (buffer == NULL) { + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); + return NULL; + } if (RegEnumKeyEx((HKEY) hKey, subKeyIndex, buffer, &size, NULL, NULL, NULL, NULL) != ERROR_SUCCESS){ free(buffer); return NULL; } result = (*env)->NewByteArray(env, size + 1); - (*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer); + if (result != NULL) { + (*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer); + } free(buffer); return result; } @@ -201,6 +230,10 @@ extern "C" { char* buffer = NULL; int error_code; buffer = (char*)malloc(maxValueNameLength); + if (buffer == NULL) { + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); + return NULL; + } error_code = RegEnumValue((HKEY) hKey, valueIndex, buffer, &size, NULL, NULL, NULL, NULL); if (error_code!= ERROR_SUCCESS){ @@ -208,7 +241,9 @@ extern "C" { return NULL; } result = (*env)->NewByteArray(env, size + 1); - (*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer); + if (result != NULL) { + (*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer); + } free(buffer); return result; } diff --git a/src/windows/native/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.c b/src/windows/native/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.c index 4d4f6f118711d0825dc8dc8dac09ccdcdd1aa843..786f8063570c141a96cab8ee3d05312e8bd654d0 100644 --- a/src/windows/native/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.c +++ b/src/windows/native/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.c @@ -53,7 +53,9 @@ JNIEXPORT void JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_init (JNIEnv *env, jclass authseq_clazz, jclass status_clazz) { ntlm_ctxHandleID = (*env)->GetFieldID(env, authseq_clazz, "ctxHandle", "J"); + CHECK_NULL(ntlm_ctxHandleID); ntlm_crdHandleID = (*env)->GetFieldID(env, authseq_clazz, "crdHandle", "J"); + CHECK_NULL(ntlm_crdHandleID); status_seqCompleteID = (*env)->GetFieldID(env, status_clazz, "sequenceComplete", "Z"); } @@ -100,6 +102,16 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_get } } pCred = (CredHandle *)malloc(sizeof (CredHandle)); + if (pCred == NULL) { + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); + if (pUser != NULL) + JNU_ReleaseStringPlatformChars(env, user, pUser); + if (pPassword != NULL) + JNU_ReleaseStringPlatformChars(env, password, pPassword); + if (pDomain != NULL) + JNU_ReleaseStringPlatformChars(env, domain, pDomain); + return NULL; + } if ( ((pUser != NULL) || (pPassword != NULL)) || (pDomain != NULL)) { pAuthId = &AuthId; @@ -177,7 +189,12 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequenc pCtx = (CtxtHandle *) (*env)->GetLongField (env, this, ntlm_ctxHandleID); if (pCtx == 0) { /* first call */ newContext = (CtxtHandle *)malloc(sizeof(CtxtHandle)); - (*env)->SetLongField (env, this, ntlm_ctxHandleID, (jlong)newContext); + if (newContext != NULL) { + (*env)->SetLongField (env, this, ntlm_ctxHandleID, (jlong)newContext); + } else { + JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); + return NULL; + } } else { newContext = pCtx; } @@ -198,6 +215,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequenc if (lastToken != 0) { pInput = (VOID *)(*env)->GetByteArrayElements(env, lastToken, &isCopy); + CHECK_NULL_RETURN(pInput, NULL); inputLen = (*env)->GetArrayLength(env, lastToken); InBuffDesc.ulVersion = 0; @@ -240,8 +258,10 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequenc if ( OutSecBuff.cbBuffer > 0 ) { jbyteArray ret = (*env)->NewByteArray(env, OutSecBuff.cbBuffer); - (*env)->SetByteArrayRegion(env, ret, 0, OutSecBuff.cbBuffer, - OutSecBuff.pvBuffer); + if (ret != NULL) { + (*env)->SetByteArrayRegion(env, ret, 0, OutSecBuff.cbBuffer, + OutSecBuff.pvBuffer); + } if (lastToken != 0) // 2nd stage endSequence (pCred, pCtx, env, status); result = ret;