8011983: [parfait] False positive: unportable format string argument mismatch in jdk/src/windows/native/com/sun/security/auth/module/nt.c
authorvinnie
Wed, 05 Feb 2014 15:58:27 +0000
changeset 22652 141565f2aafc
parent 22651 bfc6ca5245fd
child 22653 7a464b795af5
8011983: [parfait] False positive: unportable format string argument mismatch in jdk/src/windows/native/com/sun/security/auth/module/nt.c Reviewed-by: alanb
jdk/src/windows/native/com/sun/security/auth/module/nt.c
--- a/jdk/src/windows/native/com/sun/security/auth/module/nt.c	Wed Feb 05 14:14:46 2014 +0000
+++ b/jdk/src/windows/native/com/sun/security/auth/module/nt.c	Wed Feb 05 15:58:27 2014 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -43,12 +43,6 @@
 BOOL getTextualSid(PSID pSid, LPTSTR TextualSid, LPDWORD lpdwBufferLen);
 void DisplayErrorText(DWORD dwLastError);
 
-static void throwIllegalArgumentException(JNIEnv *env, const char *msg) {
-    jclass clazz = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
-    if (clazz != NULL)
-        (*env)->ThrowNew(env, clazz, msg);
-}
-
 JNIEXPORT jlong JNICALL
 Java_com_sun_security_auth_module_NTSystem_getImpersonationToken0
         (JNIEnv *env, jobject obj) {
@@ -68,6 +62,7 @@
 
     long i, j = 0;
     HANDLE tokenHandle = INVALID_HANDLE_VALUE;
+    BOOL systemError = FALSE;
 
     LPTSTR userName = NULL;             // user name
     LPTSTR userSid = NULL;              // user sid
@@ -121,59 +116,70 @@
 
     fid = (*env)->GetFieldID(env, cls, "userName", "Ljava/lang/String;");
     if (fid == 0) {
-        (*env)->ExceptionClear(env);
-        throwIllegalArgumentException(env, "invalid field: userName");
-        goto cleanup;
+        jclass newExcCls =
+            (*env)->FindClass(env, "java/lang/IllegalArgumentException");
+        if (newExcCls == 0) {
+            // Unable to find exception class
+            systemError = TRUE;
+            goto out;
+        }
+        (*env)->ThrowNew(env, newExcCls, "invalid field: userName");
     }
     jstr = (*env)->NewStringUTF(env, userName);
-    if (jstr == NULL)
-        goto cleanup;
     (*env)->SetObjectField(env, obj, fid, jstr);
 
     fid = (*env)->GetFieldID(env, cls, "userSID", "Ljava/lang/String;");
     if (fid == 0) {
-        (*env)->ExceptionClear(env);
-        throwIllegalArgumentException(env, "invalid field: userSID");
-        goto cleanup;
+        jclass newExcCls =
+            (*env)->FindClass(env, "java/lang/IllegalArgumentException");
+        if (newExcCls == 0) {
+            systemError = TRUE;
+            goto out;
+        }
+        (*env)->ThrowNew(env, newExcCls, "invalid field: userSID");
     }
     jstr = (*env)->NewStringUTF(env, userSid);
-    if (jstr == NULL)
-        goto cleanup;
     (*env)->SetObjectField(env, obj, fid, jstr);
 
     fid = (*env)->GetFieldID(env, cls, "domain", "Ljava/lang/String;");
     if (fid == 0) {
-        (*env)->ExceptionClear(env);
-        throwIllegalArgumentException(env, "invalid field: domain");
-        goto cleanup;
+        jclass newExcCls =
+            (*env)->FindClass(env, "java/lang/IllegalArgumentException");
+        if (newExcCls == 0) {
+            systemError = TRUE;
+            goto out;
+        }
+        (*env)->ThrowNew(env, newExcCls, "invalid field: domain");
     }
     jstr = (*env)->NewStringUTF(env, domainName);
-    if (jstr == NULL)
-        goto cleanup;
     (*env)->SetObjectField(env, obj, fid, jstr);
 
     if (domainSid != NULL) {
         fid = (*env)->GetFieldID(env, cls, "domainSID", "Ljava/lang/String;");
         if (fid == 0) {
-            (*env)->ExceptionClear(env);
-            throwIllegalArgumentException(env, "invalid field: domainSID");
-            goto cleanup;
+            jclass newExcCls =
+                (*env)->FindClass(env, "java/lang/IllegalArgumentException");
+            if (newExcCls == 0) {
+                systemError = TRUE;
+                goto out;
+            }
+            (*env)->ThrowNew(env, newExcCls, "invalid field: domainSID");
         }
         jstr = (*env)->NewStringUTF(env, domainSid);
-        if (jstr == NULL)
-            goto cleanup;
         (*env)->SetObjectField(env, obj, fid, jstr);
     }
 
     fid = (*env)->GetFieldID(env, cls, "primaryGroupID", "Ljava/lang/String;");
     if (fid == 0) {
-        (*env)->ExceptionClear(env);
-        throwIllegalArgumentException(env, "invalid field: PrimaryGroupID");
-        goto cleanup;
+        jclass newExcCls =
+            (*env)->FindClass(env, "java/lang/IllegalArgumentException");
+        if (newExcCls == 0) {
+            systemError = TRUE;
+            goto out;
+        }
+        (*env)->ThrowNew(env, newExcCls, "invalid field: PrimaryGroupID");
     }
     jstr = (*env)->NewStringUTF(env, primaryGroup);
-    if (jstr == NULL)
-        goto cleanup;
     (*env)->SetObjectField(env, obj, fid, jstr);
 
     // primary group may or may not be part of supplementary groups
@@ -198,14 +204,19 @@
 
         fid = (*env)->GetFieldID(env, cls, "groupIDs", "[Ljava/lang/String;");
         if (fid == 0) {
-            (*env)->ExceptionClear(env);
-            throwIllegalArgumentException(env, "groupIDs");
-            goto cleanup;
+            jclass newExcCls =
+                (*env)->FindClass(env, "java/lang/IllegalArgumentException");
+            if (newExcCls == 0) {
+                systemError = TRUE;
+                goto out;
+            }
+            (*env)->ThrowNew(env, newExcCls, "invalid field: groupIDs");
         }
 
         stringClass = (*env)->FindClass(env, "java/lang/String");
-        if (stringClass == NULL)
-            goto cleanup;
+        if (stringClass == 0) {
+            goto out;
+        }
 
         if (pIndex == -1) {
             // primary group not in groups array
@@ -215,8 +226,6 @@
             // allocate one less array entry and do not add into new array
             jgroups = (*env)->NewObjectArray(env, numGroups-1, stringClass, 0);
         }
-        if (jgroups == NULL)
-            goto cleanup;
 
         for (i = 0, j = 0; i < (long)numGroups; i++) {
             if (pIndex == i) {
@@ -224,14 +233,12 @@
                 continue;
             }
             jstr = (*env)->NewStringUTF(env, groups[i]);
-            if (jstr == NULL)
-                goto cleanup;
             (*env)->SetObjectArrayElement(env, jgroups, j++, jstr);
         }
         (*env)->SetObjectField(env, obj, fid, jgroups);
     }
 
-cleanup:
+out:
     if (userName != NULL) {
         HeapFree(GetProcessHeap(), 0, userName);
     }
@@ -257,6 +264,11 @@
     }
     CloseHandle(tokenHandle);
 
+    if (systemError && debug) {
+        printf("  [getCurrent] System Error: ");
+        printf("unable to find IllegalArgumentException class\n");
+    }
+
     return;
 }
 
@@ -324,7 +336,7 @@
             DisplayErrorText(GetLastError());
         }
         error = TRUE;
-        goto cleanup;
+        goto out;
     }
 
     if (debug) {
@@ -357,7 +369,7 @@
             DisplayErrorText(GetLastError());
         }
         error = TRUE;
-        goto cleanup;
+        goto out;
     }
 
     if (debug) {
@@ -399,7 +411,7 @@
             DisplayErrorText(GetLastError());
         }
         // ok not to have a domain SID (no error)
-        goto cleanup;
+        goto out;
     }
 
     bufSize = 0;
@@ -410,7 +422,7 @@
         printf("  [getUser] domainSid: %s\n", *domainSid);
     }
 
-cleanup:
+out:
     if (tokenUserInfo != NULL) {
         HeapFree(GetProcessHeap(), 0, tokenUserInfo);
     }
@@ -454,7 +466,7 @@
             DisplayErrorText(GetLastError());
         }
         error = TRUE;
-        goto cleanup;
+        goto out;
     }
 
     if (debug) {
@@ -469,7 +481,7 @@
         printf("  [getPrimaryGroup] primaryGroup: %s\n", *primaryGroup);
     }
 
-cleanup:
+out:
     if (tokenGroupInfo != NULL) {
         HeapFree(GetProcessHeap(), 0, tokenGroupInfo);
     }
@@ -507,7 +519,7 @@
             DisplayErrorText(GetLastError());
         }
         error = TRUE;
-        goto cleanup;
+        goto out;
     }
 
     if (debug) {
@@ -516,7 +528,7 @@
 
     if (tokenGroupInfo->GroupCount == 0) {
         // no groups
-        goto cleanup;
+        goto out;
     }
 
     // return group info
@@ -533,7 +545,7 @@
         }
     }
 
-cleanup:
+out:
     if (tokenGroupInfo != NULL) {
         HeapFree(GetProcessHeap(), 0, tokenGroupInfo);
     }
@@ -577,7 +589,8 @@
     CloseHandle(dupToken);
 
     if (debug) {
-        printf("  [getImpersonationToken] token = %d\n", *impersonationToken);
+        printf("  [getImpersonationToken] token = %p\n",
+            (void *)*impersonationToken);
     }
     return TRUE;
 }