changeset 9692:7a49291d7ac7

8036600: JNI exception pending in src/jdk/src/windows/native/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.c Summary: check JNI return values, check for pending exceptions, check malloc return value and raise OOME as needed Reviewed-by: alanb
author msheppar
date Fri, 20 Jun 2014 20:14:29 +0100
parents 7a3d9b221f8a
children f12dc751420f
files src/windows/native/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.c
diffstat 1 files changed, 23 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.c	Fri Jun 20 17:43:13 2014 +0100
+++ b/src/windows/native/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.c	Fri Jun 20 20:14:29 2014 +0100
@@ -53,7 +53,9 @@
 (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 @@
         }
     }
     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 @@
     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 @@
     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 @@
 
     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;