RFR 8017271: Crash may occur in java.net.DualStackPlainSocketImpl::initIDs due to unchecked values returned from JNI functions
Kurchi Hazra
kurchi.subhra.hazra at oracle.com
Fri Jun 21 11:24:17 PDT 2013
Looks good to me too.
On 6/21/2013 7:03 AM, Alan Bateman wrote:
> On 21/06/2013 14:50, Chris Hegarty wrote:
>> 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;
>>
> I can only assume that memory is at exhaustion point for this to
> happen but what you have is fine (we should be checking it everywhere).
>
> -Alan
--
-Kurchi
More information about the net-dev
mailing list