RFR 8017271: Crash may occur in java.net.DualStackPlainSocketImpl::initIDs due to unchecked values returned from JNI functions
Chris Hegarty
chris.hegarty at oracle.com
Fri Jun 21 06:50:45 PDT 2013
There is a remote possibility that FindClass can return NULL, for a
class we expect to exist, OOM, etc. Best practice is to check the return
value before attempting to use it.
CHECK_NULL [1] is a macro used in other places in the networking native
code for such checks. There will be a pending exception on the stack if
FindClass fails.
diff -r 4503e04141f7 src/windows/native/java/net/DualStackPlainSocketImpl.c
--- a/src/windows/native/java/net/DualStackPlainSocketImpl.c Fri Jun
21 18:26:13 2013 +0800
+++ b/src/windows/native/java/net/DualStackPlainSocketImpl.c Fri Jun
21 14:39:52 2013 +0100
@@ -43,6 +43,7 @@ JNIEXPORT void JNICALL Java_java_net_Dua
(JNIEnv *env, jclass clazz) {
jclass cls = (*env)->FindClass(env, "java/net/InetSocketAddress");
+ CHECK_NULL(cls);
isa_class = (*env)->NewGlobalRef(env, cls);
isa_ctorID = (*env)->GetMethodID(env, cls, "<init>",
"(Ljava/net/InetAddress;I)V");
-Chris.
[1] #define CHECK_NULL(x) if ((x) == NULL) return;
More information about the net-dev
mailing list