diff --git a/src/aix/classes/sun/nio/fs/AixNativeDispatcher.java b/src/aix/classes/sun/nio/fs/AixNativeDispatcher.java index d46d80fc97fce1a6653747ae7ca081e905815990..76e833ae19a78f8a9157e96078165a9c01ca84a8 100644 --- a/src/aix/classes/sun/nio/fs/AixNativeDispatcher.java +++ b/src/aix/classes/sun/nio/fs/AixNativeDispatcher.java @@ -43,7 +43,7 @@ class AixNativeDispatcher extends UnixNativeDispatcher { static native UnixMountEntry[] getmntctl() throws UnixException; // initialize - private static native int init(); + private static native void init(); static { AccessController.doPrivileged(new PrivilegedAction() { diff --git a/src/aix/native/sun/nio/fs/AixNativeDispatcher.c b/src/aix/native/sun/nio/fs/AixNativeDispatcher.c index 82d8f6203e789113ca3433c5241ec668623b0c9a..e7afb205280e9dda18afa3eb458d816a1862b7de 100644 --- a/src/aix/native/sun/nio/fs/AixNativeDispatcher.c +++ b/src/aix/native/sun/nio/fs/AixNativeDispatcher.c @@ -56,23 +56,26 @@ static void throwUnixException(JNIEnv* env, int errnum) { /** * Initialization */ -JNIEXPORT jint JNICALL +JNIEXPORT void JNICALL Java_sun_nio_fs_AixNativeDispatcher_init(JNIEnv* env, jclass this) { - jint flags = 0; jclass clazz; clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry"); - if (clazz == NULL) { - return 0; - } + CHECK_NULL(clazz); entry_name = (*env)->GetFieldID(env, clazz, "name", "[B"); + CHECK_NULL(entry_name); entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B"); + CHECK_NULL(entry_dir); entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B"); + CHECK_NULL(entry_fstype); entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B"); + CHECK_NULL(entry_options); entry_cls = (*env)->NewGlobalRef(env, clazz); - - return 0; + if (entry_cls == NULL) { + JNU_ThrowOutOfMemoryError(env, NULL); + return; + } } /** diff --git a/src/solaris/native/java/io/UnixFileSystem_md.c b/src/solaris/native/java/io/UnixFileSystem_md.c index 5f95cd998c84f5aa4898e875d60682f2357da601..487e8a2bac39fddabf48d55ee371e0eb58110cff 100644 --- a/src/solaris/native/java/io/UnixFileSystem_md.c +++ b/src/solaris/native/java/io/UnixFileSystem_md.c @@ -283,6 +283,10 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this, struct dirent64 *result; int len, maxlen; jobjectArray rv, old; + jclass str_class; + + str_class = JNU_ClassString(env); + CHECK_NULL_RETURN(str_class, NULL); WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { dir = opendir(path); @@ -299,7 +303,7 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this, /* Allocate an initial String array */ len = 0; maxlen = 16; - rv = (*env)->NewObjectArray(env, maxlen, JNU_ClassString(env), NULL); + rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL); if (rv == NULL) goto error; /* Scan the directory */ @@ -309,8 +313,7 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this, continue; if (len == maxlen) { old = rv; - rv = (*env)->NewObjectArray(env, maxlen <<= 1, - JNU_ClassString(env), NULL); + rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL); if (rv == NULL) goto error; if (JNU_CopyObjectArray(env, rv, old, len) < 0) goto error; (*env)->DeleteLocalRef(env, old); @@ -329,7 +332,7 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this, /* Copy the final results into an appropriately-sized array */ old = rv; - rv = (*env)->NewObjectArray(env, len, JNU_ClassString(env), NULL); + rv = (*env)->NewObjectArray(env, len, str_class, NULL); if (rv == NULL) { return NULL; } diff --git a/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c b/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c index 816270c9b8e07c93c50df0124ff039cc2c58e3fc..f5dd361c4fc7ef8909cd5505f26bb503acce182a 100644 --- a/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c +++ b/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c @@ -56,18 +56,28 @@ JNIEXPORT void JNICALL Java_sun_nio_ch_DatagramChannelImpl_initIDs(JNIEnv *env, jclass clazz) { clazz = (*env)->FindClass(env, "java/net/InetSocketAddress"); + CHECK_NULL(clazz); isa_class = (*env)->NewGlobalRef(env, clazz); + if (isa_class == NULL) { + JNU_ThrowOutOfMemoryError(env, NULL); + return; + } isa_ctorID = (*env)->GetMethodID(env, clazz, "", "(Ljava/net/InetAddress;I)V"); + CHECK_NULL(isa_ctorID); clazz = (*env)->FindClass(env, "sun/nio/ch/DatagramChannelImpl"); + CHECK_NULL(clazz); dci_senderID = (*env)->GetFieldID(env, clazz, "sender", "Ljava/net/SocketAddress;"); + CHECK_NULL(dci_senderID); dci_senderAddrID = (*env)->GetFieldID(env, clazz, "cachedSenderInetAddress", "Ljava/net/InetAddress;"); + CHECK_NULL(dci_senderAddrID); dci_senderPortID = (*env)->GetFieldID(env, clazz, "cachedSenderPort", "I"); + CHECK_NULL(dci_senderPortID); } JNIEXPORT void JNICALL @@ -121,7 +131,7 @@ Java_sun_nio_ch_DatagramChannelImpl_disconnect0(JNIEnv *env, jobject this, * but that is acceptable. */ if (rv < 0 && errno == EAFNOSUPPORT) - rv = errno = 0; + rv = errno = 0; #endif } #endif @@ -192,17 +202,11 @@ Java_sun_nio_ch_DatagramChannelImpl_receive0(JNIEnv *env, jobject this, if (senderAddr == NULL) { jobject isa = NULL; int port; - jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, - &port); - + jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port); if (ia != NULL) { isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port); } - - if (isa == NULL) { - JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); - return IOS_THROWN; - } + CHECK_NULL_RETURN(isa, IOS_THROWN); (*env)->SetObjectField(env, this, dci_senderAddrID, ia); (*env)->SetIntField(env, this, dci_senderPortID, diff --git a/src/solaris/native/sun/nio/ch/FileKey.c b/src/solaris/native/sun/nio/ch/FileKey.c index ddb88329ecac5cff8d5aa3a42c180be6a5abe74d..bdb42a6324b685400fd2a6893b80f7504cea56b6 100644 --- a/src/solaris/native/sun/nio/ch/FileKey.c +++ b/src/solaris/native/sun/nio/ch/FileKey.c @@ -43,8 +43,8 @@ static jfieldID key_st_ino; /* id for FileKey.st_ino */ JNIEXPORT void JNICALL Java_sun_nio_ch_FileKey_initIDs(JNIEnv *env, jclass clazz) { - key_st_dev = (*env)->GetFieldID(env, clazz, "st_dev", "J"); - key_st_ino = (*env)->GetFieldID(env, clazz, "st_ino", "J"); + CHECK_NULL(key_st_dev = (*env)->GetFieldID(env, clazz, "st_dev", "J")); + CHECK_NULL(key_st_ino = (*env)->GetFieldID(env, clazz, "st_ino", "J")); } diff --git a/src/solaris/native/sun/nio/ch/IOUtil.c b/src/solaris/native/sun/nio/ch/IOUtil.c index 7dbf010fcac4acef820e2b8fa599a6f011d89729..438bf41ddea33be56abcc9b0feaa6cd44c5f8732 100644 --- a/src/solaris/native/sun/nio/ch/IOUtil.c +++ b/src/solaris/native/sun/nio/ch/IOUtil.c @@ -42,8 +42,8 @@ static jfieldID fd_fdID; /* for jint 'fd' in java.io.FileDescriptor */ JNIEXPORT void JNICALL Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz) { - clazz = (*env)->FindClass(env, "java/io/FileDescriptor"); - fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I"); + CHECK_NULL(clazz = (*env)->FindClass(env, "java/io/FileDescriptor")); + CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I")); } JNIEXPORT jboolean JNICALL diff --git a/src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c b/src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c index 7a730cc0b251c0bd57e3bd73b7f84033cf9a307d..e96c9b0cc0a5d1e148129045b77724522f1a73ec 100644 --- a/src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c +++ b/src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c @@ -57,12 +57,20 @@ Java_sun_nio_ch_ServerSocketChannelImpl_initIDs(JNIEnv *env, jclass c) jclass cls; cls = (*env)->FindClass(env, "java/io/FileDescriptor"); + CHECK_NULL(cls); fd_fdID = (*env)->GetFieldID(env, cls, "fd", "I"); + CHECK_NULL(fd_fdID); cls = (*env)->FindClass(env, "java/net/InetSocketAddress"); + CHECK_NULL(cls); isa_class = (*env)->NewGlobalRef(env, cls); + if (isa_class == NULL) { + JNU_ThrowOutOfMemoryError(env, NULL); + return; + } isa_ctorID = (*env)->GetMethodID(env, cls, "", "(Ljava/net/InetAddress;I)V"); + CHECK_NULL(isa_ctorID); } JNIEXPORT jint JNICALL @@ -79,6 +87,10 @@ Java_sun_nio_ch_ServerSocketChannelImpl_accept0(JNIEnv *env, jobject this, jint remote_port; NET_AllocSockaddr(&sa, &alloc_len); + if (sa == NULL) { + JNU_ThrowOutOfMemoryError(env, NULL); + return IOS_THROWN; + } /* * accept connection but ignore ECONNABORTED indicating that @@ -110,8 +122,9 @@ Java_sun_nio_ch_ServerSocketChannelImpl_accept0(JNIEnv *env, jobject this, (*env)->SetIntField(env, newfdo, fd_fdID, newfd); remote_ia = NET_SockaddrToInetAddress(env, sa, (int *)&remote_port); free((void *)sa); - isa = (*env)->NewObject(env, isa_class, isa_ctorID, - remote_ia, remote_port); + CHECK_NULL_RETURN(remote_ia, IOS_THROWN); + isa = (*env)->NewObject(env, isa_class, isa_ctorID, remote_ia, remote_port); + CHECK_NULL_RETURN(isa, IOS_THROWN); (*env)->SetObjectArrayElement(env, isaa, 0, isa); return 1; } diff --git a/src/solaris/native/sun/nio/ch/sctp/SctpChannelImpl.c b/src/solaris/native/sun/nio/ch/sctp/SctpChannelImpl.c index 2ccf0f89b852cf2b08c90ecc0c4abf5b6424f82e..c74af9607f10862fdfcd0dfa09def94fe772e18c 100644 --- a/src/solaris/native/sun/nio/ch/sctp/SctpChannelImpl.c +++ b/src/solaris/native/sun/nio/ch/sctp/SctpChannelImpl.c @@ -213,6 +213,7 @@ void handleSendFailed /* retrieved address from sockaddr */ isaObj = SockAddrToInetSocketAddress(env, sap); + CHECK_NULL(isaObj); /* data retrieved from sff_data */ if (dataLength > 0) { @@ -337,6 +338,7 @@ void handlePeerAddrChange } addressObj = SockAddrToInetSocketAddress(env, (struct sockaddr*)&spc->spc_aaddr); + CHECK_NULL(addressObj); /* create PeerAddressChanged */ resultObj = (*env)->NewObject(env, spc_class, spc_ctrID, spc->spc_assoc_id, @@ -393,6 +395,7 @@ void handleMessage } isa = SockAddrToInetSocketAddress(env, sap); + CHECK_NULL(isa); getControlData(msg, cdata); /* create MessageInfoImpl */ @@ -613,4 +616,3 @@ JNIEXPORT jint JNICALL Java_sun_nio_ch_sctp_SctpChannelImpl_checkConnect return Java_sun_nio_ch_SocketChannelImpl_checkConnect(env, this, fdo, block, ready); } - diff --git a/src/solaris/native/sun/nio/ch/sctp/SctpNet.c b/src/solaris/native/sun/nio/ch/sctp/SctpNet.c index 57c4fae4fa5bf0b955c813bec13d0d94ccc07a90..f03be57b5d078772ad0d104374437245f45aa029 100644 --- a/src/solaris/native/sun/nio/ch/sctp/SctpNet.c +++ b/src/solaris/native/sun/nio/ch/sctp/SctpNet.c @@ -382,8 +382,9 @@ JNIEXPORT jobjectArray JNICALL Java_sun_nio_ch_sctp_SctpNet_getLocalAddresses0 ia = NET_SockaddrToInetAddress(env, sap, &port); if (ia != NULL) isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port); - if (isa != NULL) - (*env)->SetObjectArrayElement(env, isaa, i, isa); + if (isa == NULL) + break; + (*env)->SetObjectArrayElement(env, isaa, i, isa); if (sap->sa_family == AF_INET) addr_buf = ((struct sockaddr_in*)addr_buf) + 1; @@ -433,8 +434,9 @@ jobjectArray getRemoteAddresses ia = NET_SockaddrToInetAddress(env, sap, &port); if (ia != NULL) isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port); - if (isa != NULL) - (*env)->SetObjectArrayElement(env, isaa, i, isa); + if (isa == NULL) + break; + (*env)->SetObjectArrayElement(env, isaa, i, isa); if (sap->sa_family == AF_INET) addr_buf = ((struct sockaddr_in*)addr_buf) + 1; diff --git a/src/solaris/native/sun/nio/fs/BsdNativeDispatcher.c b/src/solaris/native/sun/nio/fs/BsdNativeDispatcher.c index 0b4f2a74dff564f1d18942a3bfb2c3056c097785..9453f75d3def558502afe63e43d3dc6ca6f92c6c 100644 --- a/src/solaris/native/sun/nio/fs/BsdNativeDispatcher.c +++ b/src/solaris/native/sun/nio/fs/BsdNativeDispatcher.c @@ -72,13 +72,15 @@ Java_sun_nio_fs_BsdNativeDispatcher_initIDs(JNIEnv* env, jclass this) jclass clazz; clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry"); - if (clazz == NULL) { - return; - } + CHECK_NULL(clazz); entry_name = (*env)->GetFieldID(env, clazz, "name", "[B"); + CHECK_NULL(entry_name); entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B"); + CHECK_NULL(entry_dir); entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B"); + CHECK_NULL(entry_fstype); entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B"); + CHECK_NULL(entry_options); } JNIEXPORT jlong JNICALL @@ -201,4 +203,3 @@ Java_sun_nio_fs_BsdNativeDispatcher_endfsstat(JNIEnv* env, jclass this, jlong va free(iter); } } - diff --git a/src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c b/src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c index 1de7d5b3c98957c5b224fcb129091a2da8a7047f..c8500db5c877e63aea7cb71c598230c3d4bae77d 100644 --- a/src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c +++ b/src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c @@ -68,13 +68,15 @@ Java_sun_nio_fs_LinuxNativeDispatcher_init(JNIEnv *env, jclass clazz) my_flistxattr_func = (flistxattr_func*)dlsym(RTLD_DEFAULT, "flistxattr"); clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry"); - if (clazz == NULL) - return; - + CHECK_NULL(clazz); entry_name = (*env)->GetFieldID(env, clazz, "name", "[B"); + CHECK_NULL(entry_name); entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B"); + CHECK_NULL(entry_dir); entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B"); + CHECK_NULL(entry_fstype); entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B"); + CHECK_NULL(entry_options); } JNIEXPORT jint JNICALL diff --git a/src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c b/src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c index 1480ea9046b6c4a18cd47df668ab39187f6e3c5b..de04bbddc7c1c61d6c457a95e1c3d49612ebcdf3 100644 --- a/src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c +++ b/src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c @@ -55,14 +55,17 @@ static void throwUnixException(JNIEnv* env, int errnum) { JNIEXPORT void JNICALL Java_sun_nio_fs_SolarisNativeDispatcher_init(JNIEnv *env, jclass clazz) { clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry"); - if (clazz == NULL) - return; - + CHECK_NULL(clazz); entry_name = (*env)->GetFieldID(env, clazz, "name", "[B"); + CHECK_NULL(entry_name); entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B"); + CHECK_NULL(entry_dir); entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B"); + CHECK_NULL(entry_fstype); entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B"); + CHECK_NULL(entry_options); entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J"); + CHECK_NULL(entry_dev); } JNIEXPORT jint JNICALL diff --git a/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c b/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c index c06efaf59117f52342092b2be2309192ea9fa866..e8a1623a87de4b030c87af1090fe17b88fb24de9 100644 --- a/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c +++ b/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c @@ -179,46 +179,64 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this) jclass clazz; clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileAttributes"); - if (clazz == NULL) { - return 0; - } + CHECK_NULL_RETURN(clazz, 0); attrs_st_mode = (*env)->GetFieldID(env, clazz, "st_mode", "I"); + CHECK_NULL_RETURN(attrs_st_mode, 0); attrs_st_ino = (*env)->GetFieldID(env, clazz, "st_ino", "J"); + CHECK_NULL_RETURN(attrs_st_ino, 0); attrs_st_dev = (*env)->GetFieldID(env, clazz, "st_dev", "J"); + CHECK_NULL_RETURN(attrs_st_dev, 0); attrs_st_rdev = (*env)->GetFieldID(env, clazz, "st_rdev", "J"); + CHECK_NULL_RETURN(attrs_st_rdev, 0); attrs_st_nlink = (*env)->GetFieldID(env, clazz, "st_nlink", "I"); + CHECK_NULL_RETURN(attrs_st_nlink, 0); attrs_st_uid = (*env)->GetFieldID(env, clazz, "st_uid", "I"); + CHECK_NULL_RETURN(attrs_st_uid, 0); attrs_st_gid = (*env)->GetFieldID(env, clazz, "st_gid", "I"); + CHECK_NULL_RETURN(attrs_st_gid, 0); attrs_st_size = (*env)->GetFieldID(env, clazz, "st_size", "J"); + CHECK_NULL_RETURN(attrs_st_size, 0); attrs_st_atime_sec = (*env)->GetFieldID(env, clazz, "st_atime_sec", "J"); + CHECK_NULL_RETURN(attrs_st_atime_sec, 0); attrs_st_atime_nsec = (*env)->GetFieldID(env, clazz, "st_atime_nsec", "J"); + CHECK_NULL_RETURN(attrs_st_atime_nsec, 0); attrs_st_mtime_sec = (*env)->GetFieldID(env, clazz, "st_mtime_sec", "J"); + CHECK_NULL_RETURN(attrs_st_mtime_sec, 0); attrs_st_mtime_nsec = (*env)->GetFieldID(env, clazz, "st_mtime_nsec", "J"); + CHECK_NULL_RETURN(attrs_st_mtime_nsec, 0); attrs_st_ctime_sec = (*env)->GetFieldID(env, clazz, "st_ctime_sec", "J"); + CHECK_NULL_RETURN(attrs_st_ctime_sec, 0); attrs_st_ctime_nsec = (*env)->GetFieldID(env, clazz, "st_ctime_nsec", "J"); + CHECK_NULL_RETURN(attrs_st_ctime_nsec, 0); #ifdef _DARWIN_FEATURE_64_BIT_INODE attrs_st_birthtime_sec = (*env)->GetFieldID(env, clazz, "st_birthtime_sec", "J"); + CHECK_NULL_RETURN(attrs_st_birthtime_sec, 0); #endif clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileStoreAttributes"); - if (clazz == NULL) { - return 0; - } + CHECK_NULL_RETURN(clazz, 0); attrs_f_frsize = (*env)->GetFieldID(env, clazz, "f_frsize", "J"); + CHECK_NULL_RETURN(attrs_f_frsize, 0); attrs_f_blocks = (*env)->GetFieldID(env, clazz, "f_blocks", "J"); + CHECK_NULL_RETURN(attrs_f_blocks, 0); attrs_f_bfree = (*env)->GetFieldID(env, clazz, "f_bfree", "J"); + CHECK_NULL_RETURN(attrs_f_bfree, 0); attrs_f_bavail = (*env)->GetFieldID(env, clazz, "f_bavail", "J"); + CHECK_NULL_RETURN(attrs_f_bavail, 0); clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry"); - if (clazz == NULL) { - return 0; - } + CHECK_NULL_RETURN(clazz, 0); entry_name = (*env)->GetFieldID(env, clazz, "name", "[B"); + CHECK_NULL_RETURN(entry_name, 0); entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B"); + CHECK_NULL_RETURN(entry_dir, 0); entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B"); + CHECK_NULL_RETURN(entry_fstype, 0); entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B"); + CHECK_NULL_RETURN(entry_options, 0); entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J"); + CHECK_NULL_RETURN(entry_dev, 0); /* system calls that might not be available at run time */ diff --git a/src/windows/native/java/io/FileDescriptor_md.c b/src/windows/native/java/io/FileDescriptor_md.c index 221bf1d92174e51fe07f3d0f01fb8eb5e50fb48c..db04cd476535e4e624c977dfc7bac64df85ee60a 100644 --- a/src/windows/native/java/io/FileDescriptor_md.c +++ b/src/windows/native/java/io/FileDescriptor_md.c @@ -48,8 +48,8 @@ jfieldID IO_handle_fdID; JNIEXPORT void JNICALL Java_java_io_FileDescriptor_initIDs(JNIEnv *env, jclass fdClass) { - IO_fd_fdID = (*env)->GetFieldID(env, fdClass, "fd", "I"); - IO_handle_fdID = (*env)->GetFieldID(env, fdClass, "handle", "J"); + CHECK_NULL(IO_fd_fdID = (*env)->GetFieldID(env, fdClass, "fd", "I")); + CHECK_NULL(IO_handle_fdID = (*env)->GetFieldID(env, fdClass, "handle", "J")); } JNIEXPORT jlong JNICALL diff --git a/src/windows/native/java/io/WinNTFileSystem_md.c b/src/windows/native/java/io/WinNTFileSystem_md.c index 2a0d477a7d2bc999a6bcbe50eee43ce920a8534d..d86183ed738d5bac003bb733baf5d735e5e02dcb 100644 --- a/src/windows/native/java/io/WinNTFileSystem_md.c +++ b/src/windows/native/java/io/WinNTFileSystem_md.c @@ -59,10 +59,12 @@ JNIEXPORT void JNICALL Java_java_io_WinNTFileSystem_initIDs(JNIEnv *env, jclass cls) { HMODULE handle; - jclass fileClass = (*env)->FindClass(env, "java/io/File"); - if (!fileClass) return; - ids.path = - (*env)->GetFieldID(env, fileClass, "path", "Ljava/lang/String;"); + jclass fileClass; + + fileClass = (*env)->FindClass(env, "java/io/File"); + CHECK_NULL(fileClass); + ids.path = (*env)->GetFieldID(env, fileClass, "path", "Ljava/lang/String;"); + CHECK_NULL(ids.path); // GetFinalPathNameByHandle requires Windows Vista or newer if (GetModuleHandleExW((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | @@ -247,8 +249,8 @@ Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this, WCHAR canonicalPath[MAX_PATH_LENGTH]; WITH_UNICODE_STRING(env, pathname, path) { - /*we estimate the max length of memory needed as - "currentDir. length + pathname.length" + /* we estimate the max length of memory needed as + "currentDir. length + pathname.length" */ int len = (int)wcslen(path); len += currentDirLength(path, len); @@ -262,12 +264,11 @@ Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this, } else { JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); } - } else - if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) { + } else if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) { rv = (*env)->NewString(env, canonicalPath, (jsize)wcslen(canonicalPath)); } } END_UNICODE_STRING(env, path); - if (rv == NULL) { + if (rv == NULL && !(*env)->ExceptionCheck(env)) { JNU_ThrowIOExceptionWithLastError(env, "Bad pathname"); } return rv; @@ -296,15 +297,14 @@ Java_java_io_WinNTFileSystem_canonicalizeWithPrefix0(JNIEnv *env, jobject this, } else { JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); } - } else - if (wcanonicalizeWithPrefix(canonicalPrefix, - pathWithCanonicalPrefix, - canonicalPath, MAX_PATH_LENGTH) >= 0) { + } else if (wcanonicalizeWithPrefix(canonicalPrefix, + pathWithCanonicalPrefix, + canonicalPath, MAX_PATH_LENGTH) >= 0) { rv = (*env)->NewString(env, canonicalPath, (jsize)wcslen(canonicalPath)); } } END_UNICODE_STRING(env, pathWithCanonicalPrefix); } END_UNICODE_STRING(env, canonicalPrefix); - if (rv == NULL) { + if (rv == NULL && !(*env)->ExceptionCheck(env)) { JNU_ThrowIOExceptionWithLastError(env, "Bad pathname"); } return rv; @@ -624,8 +624,13 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) jobjectArray rv, old; DWORD fattr; jstring name; + jclass str_class; + WCHAR *pathbuf; - WCHAR *pathbuf = fileToNTPath(env, file, ids.path); + str_class = JNU_ClassString(env); + CHECK_NULL_RETURN(str_class, NULL); + + pathbuf = fileToNTPath(env, file, ids.path); if (pathbuf == NULL) return NULL; search_path = (WCHAR*)malloc(2*wcslen(pathbuf) + 6); @@ -673,7 +678,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) return NULL; } else { // No files found - return an empty array - rv = (*env)->NewObjectArray(env, 0, JNU_ClassString(env), NULL); + rv = (*env)->NewObjectArray(env, 0, str_class, NULL); return rv; } } @@ -681,7 +686,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) /* Allocate an initial String array */ len = 0; maxlen = 16; - rv = (*env)->NewObjectArray(env, maxlen, JNU_ClassString(env), NULL); + rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL); if (rv == NULL) // Couldn't allocate an array return NULL; /* Scan the directory */ @@ -695,10 +700,8 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) return NULL; // error; if (len == maxlen) { old = rv; - rv = (*env)->NewObjectArray(env, maxlen <<= 1, - JNU_ClassString(env), NULL); - if ( rv == NULL - || JNU_CopyObjectArray(env, rv, old, len) < 0) + rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL); + if (rv == NULL || JNU_CopyObjectArray(env, rv, old, len) < 0) return NULL; // error (*env)->DeleteLocalRef(env, old); } @@ -713,7 +716,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) /* Copy the final results into an appropriately-sized array */ old = rv; - rv = (*env)->NewObjectArray(env, len, JNU_ClassString(env), NULL); + rv = (*env)->NewObjectArray(env, len, str_class, NULL); if (rv == NULL) return NULL; /* error */ if (JNU_CopyObjectArray(env, rv, old, len) < 0) diff --git a/src/windows/native/sun/nio/ch/DatagramChannelImpl.c b/src/windows/native/sun/nio/ch/DatagramChannelImpl.c index ab46f8d7faa57721ee811fdcc20c22afe22cc9f7..ecc96a1d8bb2092845fe0c8661f2cc904250c85a 100644 --- a/src/windows/native/sun/nio/ch/DatagramChannelImpl.c +++ b/src/windows/native/sun/nio/ch/DatagramChannelImpl.c @@ -45,18 +45,28 @@ JNIEXPORT void JNICALL Java_sun_nio_ch_DatagramChannelImpl_initIDs(JNIEnv *env, jclass clazz) { clazz = (*env)->FindClass(env, "java/net/InetSocketAddress"); + CHECK_NULL(clazz); isa_class = (*env)->NewGlobalRef(env, clazz); + if (isa_class == NULL) { + JNU_ThrowOutOfMemoryError(env, NULL); + return; + } isa_ctorID = (*env)->GetMethodID(env, clazz, "", "(Ljava/net/InetAddress;I)V"); + CHECK_NULL(isa_ctorID); clazz = (*env)->FindClass(env, "sun/nio/ch/DatagramChannelImpl"); + CHECK_NULL(clazz); dci_senderID = (*env)->GetFieldID(env, clazz, "sender", "Ljava/net/SocketAddress;"); + CHECK_NULL(dci_senderID); dci_senderAddrID = (*env)->GetFieldID(env, clazz, "cachedSenderInetAddress", "Ljava/net/InetAddress;"); + CHECK_NULL(dci_senderAddrID); dci_senderPortID = (*env)->GetFieldID(env, clazz, "cachedSenderPort", "I"); + CHECK_NULL(dci_senderPortID); } /* @@ -185,17 +195,11 @@ Java_sun_nio_ch_DatagramChannelImpl_receive0(JNIEnv *env, jobject this, if (senderAddr == NULL) { jobject isa = NULL; int port; - jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, - &port); - + jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port); if (ia != NULL) { isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port); } - - if (isa == NULL) { - JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); - return IOS_THROWN; - } + CHECK_NULL_RETURN(isa, IOS_THROWN); // update cachedSenderInetAddress/cachedSenderPort (*env)->SetObjectField(env, this, dci_senderAddrID, ia); diff --git a/src/windows/native/sun/nio/ch/FileKey.c b/src/windows/native/sun/nio/ch/FileKey.c index e095296abeb03e2487e41f44b69fb2881f545c18..65306d1d6398f48876a3bf4f70d4981ac00b187f 100644 --- a/src/windows/native/sun/nio/ch/FileKey.c +++ b/src/windows/native/sun/nio/ch/FileKey.c @@ -38,9 +38,9 @@ static jfieldID key_indexLow; /* id for FileKey.nFileIndexLow */ JNIEXPORT void JNICALL Java_sun_nio_ch_FileKey_initIDs(JNIEnv *env, jclass clazz) { - key_volumeSN = (*env)->GetFieldID(env, clazz, "dwVolumeSerialNumber", "J"); - key_indexHigh = (*env)->GetFieldID(env, clazz, "nFileIndexHigh", "J"); - key_indexLow = (*env)->GetFieldID(env, clazz, "nFileIndexLow", "J"); + CHECK_NULL(key_volumeSN = (*env)->GetFieldID(env, clazz, "dwVolumeSerialNumber", "J")); + CHECK_NULL(key_indexHigh = (*env)->GetFieldID(env, clazz, "nFileIndexHigh", "J")); + CHECK_NULL(key_indexLow = (*env)->GetFieldID(env, clazz, "nFileIndexLow", "J")); } diff --git a/src/windows/native/sun/nio/ch/IOUtil.c b/src/windows/native/sun/nio/ch/IOUtil.c index 10c72e4682fba8ca3adea958b83e02a50eb79380..370dcf5e23f0a2a7e161bca9261ff1b8aad412ae 100644 --- a/src/windows/native/sun/nio/ch/IOUtil.c +++ b/src/windows/native/sun/nio/ch/IOUtil.c @@ -52,9 +52,9 @@ Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed JNIEXPORT void JNICALL Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz) { - clazz = (*env)->FindClass(env, "java/io/FileDescriptor"); - fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I"); - handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J"); + 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")); } /************************************************************** diff --git a/src/windows/native/sun/nio/ch/Iocp.c b/src/windows/native/sun/nio/ch/Iocp.c index 8f87a8937f764da7a5828ba3985df836d59ee15a..f95562340755c967a110f8bc127d6772e2251ff3 100644 --- a/src/windows/native/sun/nio/ch/Iocp.c +++ b/src/windows/native/sun/nio/ch/Iocp.c @@ -46,16 +46,15 @@ Java_sun_nio_ch_Iocp_initIDs(JNIEnv* env, jclass this) jclass clazz; clazz = (*env)->FindClass(env, "sun/nio/ch/Iocp$CompletionStatus"); - if (clazz == NULL) { - return; - } + CHECK_NULL(clazz); completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I"); - if (completionStatus_error == NULL) return; + CHECK_NULL(completionStatus_error); completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I"); - if (completionStatus_bytesTransferred == NULL) return; + CHECK_NULL(completionStatus_bytesTransferred); completionStatus_completionKey = (*env)->GetFieldID(env, clazz, "completionKey", "I"); - if (completionStatus_completionKey == NULL) return; + CHECK_NULL(completionStatus_completionKey); completionStatus_overlapped = (*env)->GetFieldID(env, clazz, "overlapped", "J"); + CHECK_NULL(completionStatus_overlapped); } JNIEXPORT jint JNICALL diff --git a/src/windows/native/sun/nio/ch/ServerSocketChannelImpl.c b/src/windows/native/sun/nio/ch/ServerSocketChannelImpl.c index 2af833c2eb76a8ce673f0c4e58f8b0fb1d8b9c67..30d6d641645a54c6951356f3d5ea418b32ec96e6 100644 --- a/src/windows/native/sun/nio/ch/ServerSocketChannelImpl.c +++ b/src/windows/native/sun/nio/ch/ServerSocketChannelImpl.c @@ -56,12 +56,20 @@ JNIEXPORT void JNICALL Java_sun_nio_ch_ServerSocketChannelImpl_initIDs(JNIEnv *env, jclass cls) { cls = (*env)->FindClass(env, "java/io/FileDescriptor"); + CHECK_NULL(cls); fd_fdID = (*env)->GetFieldID(env, cls, "fd", "I"); + CHECK_NULL(fd_fdID); cls = (*env)->FindClass(env, "java/net/InetSocketAddress"); + CHECK_NULL(cls); isa_class = (*env)->NewGlobalRef(env, cls); + if (isa_class == NULL) { + JNU_ThrowOutOfMemoryError(env, NULL); + return; + } isa_ctorID = (*env)->GetMethodID(env, cls, "", "(Ljava/net/InetAddress;I)V"); + CHECK_NULL(isa_ctorID); } JNIEXPORT void JNICALL @@ -99,10 +107,10 @@ Java_sun_nio_ch_ServerSocketChannelImpl_accept0(JNIEnv *env, jobject this, (*env)->SetIntField(env, newfdo, fd_fdID, newfd); remote_ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, (int *)&remote_port); + CHECK_NULL_RETURN(remote_ia, IOS_THROWN); - isa = (*env)->NewObject(env, isa_class, isa_ctorID, - remote_ia, remote_port); + isa = (*env)->NewObject(env, isa_class, isa_ctorID, remote_ia, remote_port); + CHECK_NULL_RETURN(isa, IOS_THROWN); (*env)->SetObjectArrayElement(env, isaa, 0, isa); - return 1; } diff --git a/src/windows/native/sun/nio/ch/SocketChannelImpl.c b/src/windows/native/sun/nio/ch/SocketChannelImpl.c index a8ba14bdf607b41f7adb31a3d2d1fb31e27ce476..4ba86a942e90040d71c70c59dcc057d3ff30ce04 100644 --- a/src/windows/native/sun/nio/ch/SocketChannelImpl.c +++ b/src/windows/native/sun/nio/ch/SocketChannelImpl.c @@ -42,8 +42,8 @@ static jfieldID ia_addrID; /* java.net.InetAddress.address */ JNIEXPORT void JNICALL Java_sun_nio_ch_SocketChannelImpl_initIDs(JNIEnv *env, jclass cls) { - cls = (*env)->FindClass(env, "java/net/InetAddress"); - ia_addrID = (*env)->GetFieldID(env, cls, "address", "I"); + CHECK_NULL(cls = (*env)->FindClass(env, "java/net/InetAddress")); + CHECK_NULL(ia_addrID = (*env)->GetFieldID(env, cls, "address", "I")); } jint diff --git a/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c b/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c index 566d2aeca325fcc0a9d2d4bb28300e7367c770e7..94e060fa1933daf12f234249e21a6176f841d628 100644 --- a/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c +++ b/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c @@ -111,65 +111,70 @@ Java_sun_nio_fs_WindowsNativeDispatcher_initIDs(JNIEnv* env, jclass this) HMODULE h; clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$FirstFile"); - if (clazz == NULL) { - return; - } + CHECK_NULL(clazz); findFirst_handle = (*env)->GetFieldID(env, clazz, "handle", "J"); + CHECK_NULL(findFirst_handle); findFirst_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;"); + CHECK_NULL(findFirst_name); findFirst_attributes = (*env)->GetFieldID(env, clazz, "attributes", "I"); + CHECK_NULL(findFirst_attributes); clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$FirstStream"); - if (clazz == NULL) { - return; - } + CHECK_NULL(clazz); findStream_handle = (*env)->GetFieldID(env, clazz, "handle", "J"); + CHECK_NULL(findStream_handle); findStream_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;"); + CHECK_NULL(findStream_name); clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$VolumeInformation"); - if (clazz == NULL) { - return; - } + CHECK_NULL(clazz); volumeInfo_fsName = (*env)->GetFieldID(env, clazz, "fileSystemName", "Ljava/lang/String;"); + CHECK_NULL(volumeInfo_fsName); volumeInfo_volName = (*env)->GetFieldID(env, clazz, "volumeName", "Ljava/lang/String;"); + CHECK_NULL(volumeInfo_volName); volumeInfo_volSN = (*env)->GetFieldID(env, clazz, "volumeSerialNumber", "I"); + CHECK_NULL(volumeInfo_volSN); volumeInfo_flags = (*env)->GetFieldID(env, clazz, "flags", "I"); + CHECK_NULL(volumeInfo_flags); clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$DiskFreeSpace"); - if (clazz == NULL) { - return; - } + CHECK_NULL(clazz); diskSpace_bytesAvailable = (*env)->GetFieldID(env, clazz, "freeBytesAvailable", "J"); + CHECK_NULL(diskSpace_bytesAvailable); diskSpace_totalBytes = (*env)->GetFieldID(env, clazz, "totalNumberOfBytes", "J"); + CHECK_NULL(diskSpace_totalBytes); diskSpace_totalFree = (*env)->GetFieldID(env, clazz, "totalNumberOfFreeBytes", "J"); + CHECK_NULL(diskSpace_totalFree); clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$Account"); - if (clazz == NULL) { - return; - } + CHECK_NULL(clazz); account_domain = (*env)->GetFieldID(env, clazz, "domain", "Ljava/lang/String;"); + CHECK_NULL(account_domain); account_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;"); + CHECK_NULL(account_name); account_use = (*env)->GetFieldID(env, clazz, "use", "I"); + CHECK_NULL(account_use); clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$AclInformation"); - if (clazz == NULL) { - return; - } + CHECK_NULL(clazz); aclInfo_aceCount = (*env)->GetFieldID(env, clazz, "aceCount", "I"); + CHECK_NULL(aclInfo_aceCount); clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$CompletionStatus"); - if (clazz == NULL) { - return; - } + CHECK_NULL(clazz); completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I"); + CHECK_NULL(completionStatus_error); completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I"); + CHECK_NULL(completionStatus_bytesTransferred); completionStatus_completionKey = (*env)->GetFieldID(env, clazz, "completionKey", "J"); + CHECK_NULL(completionStatus_completionKey); clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$BackupResult"); - if (clazz == NULL) { - return; - } + CHECK_NULL(clazz); backupResult_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I"); + CHECK_NULL(backupResult_bytesTransferred); backupResult_context = (*env)->GetFieldID(env, clazz, "context", "J"); + CHECK_NULL(backupResult_context); // get handle to kernel32 if (GetModuleHandleExW((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |