changeset 21620:5f7f2b541560

8027961: Inet[4|6]Address native initializing code should check field/MethodID values Reviewed-by: michaelm, rriggs
author chegar
date Thu, 07 Nov 2013 08:23:00 +0000
parents bd60e99ca531
children 3101c2e7e705
files jdk/src/share/native/java/net/Inet4Address.c jdk/src/share/native/java/net/Inet6Address.c jdk/src/share/native/java/net/InetAddress.c jdk/src/solaris/native/java/net/Inet4AddressImpl.c jdk/src/solaris/native/java/net/Inet6AddressImpl.c jdk/src/windows/native/java/net/Inet4AddressImpl.c jdk/src/windows/native/java/net/Inet6AddressImpl.c
diffstat 7 files changed, 40 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/share/native/java/net/Inet4Address.c	Thu Nov 07 08:04:36 2013 +0000
+++ b/jdk/src/share/native/java/net/Inet4Address.c	Thu Nov 07 08:23:00 2013 +0000
@@ -46,5 +46,4 @@
     ia4_class = (*env)->NewGlobalRef(env, c);
     CHECK_NULL(ia4_class);
     ia4_ctrID = (*env)->GetMethodID(env, ia4_class, "<init>", "()V");
-    CHECK_NULL(ia4_ctrID);
 }
--- a/jdk/src/share/native/java/net/Inet6Address.c	Thu Nov 07 08:04:36 2013 +0000
+++ b/jdk/src/share/native/java/net/Inet6Address.c	Thu Nov 07 08:23:00 2013 +0000
@@ -65,9 +65,8 @@
     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_scopeidID);
+    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);
 }
--- a/jdk/src/share/native/java/net/InetAddress.c	Thu Nov 07 08:04:36 2013 +0000
+++ b/jdk/src/share/native/java/net/InetAddress.c	Thu Nov 07 08:23:00 2013 +0000
@@ -64,5 +64,4 @@
     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);
 }
--- a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c	Thu Nov 07 08:04:36 2013 +0000
+++ b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c	Thu Nov 07 08:23:00 2013 +0000
@@ -55,17 +55,23 @@
 static jclass ni_ia4cls;
 static jmethodID ni_ia4ctrID;
 
-static void initializeInetClasses(JNIEnv *env)
+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;
 }
 
 
@@ -141,7 +147,8 @@
     int error=0;
     struct addrinfo hints, *res, *resNew = NULL;
 
-    initializeInetClasses(env);
+    if (!initializeInetClasses(env))
+        return NULL;
 
     if (IS_NULL(host)) {
         JNU_ThrowNullPointerException(env, "host is null");
@@ -400,7 +407,8 @@
     int error = 0;
     struct addrinfo hints, *res, *resNew = NULL;
 
-    initializeInetClasses(env);
+    if (!initializeInetClasses(env))
+        return NULL;
 
     if (IS_NULL(host)) {
         JNU_ThrowNullPointerException(env, "host is null");
--- a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c	Thu Nov 07 08:04:36 2013 +0000
+++ b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c	Thu Nov 07 08:23:00 2013 +0000
@@ -124,25 +124,35 @@
 static jmethodID ni_ia6ctrID;
 static jboolean preferIPv6Address;
 
-static void initializeInetClasses(JNIEnv *env)
+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
@@ -160,7 +170,8 @@
     jobject name;
 
     // Make sure static variables we need are set.
-    initializeInetClasses(env);
+    if (!initializeInetClasses(env))
+        return NULL;
 
     /* If the requested name matches this host's hostname, return IP addresses
      * from all attached interfaces. (#2844683 et al) This prevents undesired
@@ -286,7 +297,8 @@
     struct addrinfo hints, *res, *resNew = NULL;
 #endif /* AF_INET6 */
 
-    initializeInetClasses(env);
+    if (!initializeInetClasses(env))
+        return NULL;
 
     if (IS_NULL(host)) {
         JNU_ThrowNullPointerException(env, "host is null");
--- a/jdk/src/windows/native/java/net/Inet4AddressImpl.c	Thu Nov 07 08:04:36 2013 +0000
+++ b/jdk/src/windows/native/java/net/Inet4AddressImpl.c	Thu Nov 07 08:23:00 2013 +0000
@@ -142,10 +142,15 @@
 
     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;
     }
 
--- a/jdk/src/windows/native/java/net/Inet6AddressImpl.c	Thu Nov 07 08:04:36 2013 +0000
+++ b/jdk/src/windows/native/java/net/Inet6AddressImpl.c	Thu Nov 07 08:23:00 2013 +0000
@@ -93,13 +93,21 @@
 
     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;
     }
     if (IS_NULL(host)) {