8031586: Check jdk/src/*/native/com/sun/security/auth/module for pending JNI exceptions

Reviewed-by: vinnie, chegar
This commit is contained in:
Alan Bateman 2014-02-05 10:20:30 +00:00
parent 91a6e1b092
commit e8f1f33e46
3 changed files with 82 additions and 92 deletions

View File

@ -32,6 +32,12 @@
#include <string.h>
#include <pwd.h>
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 void JNICALL
Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo
(JNIEnv *env, jobject obj) {
@ -51,7 +57,7 @@ Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo
if (groups == NULL) {
jclass cls = (*env)->FindClass(env,"java/lang/OutOfMemoryError");
if(cls != 0)
if (cls != NULL)
(*env)->ThrowNew(env, cls, NULL);
return;
}
@ -67,15 +73,13 @@ Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo
*/
fid = (*env)->GetFieldID(env, cls, "username", "Ljava/lang/String;");
if (fid == 0) {
jclass newExcCls =
(*env)->FindClass(env, "java/lang/IllegalArgumentException");
if (newExcCls == 0) {
/* Unable to find the new exception class, give up. */
return;
}
(*env)->ThrowNew(env, newExcCls, "invalid field: username");
(*env)->ExceptionClear(env);
throwIllegalArgumentException(env, "invalid field: username");
return;
}
jstr = (*env)->NewStringUTF(env, pwd.pw_name);
if (jstr == NULL)
return;
(*env)->SetObjectField(env, obj, fid, jstr);
/*
@ -83,13 +87,9 @@ Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo
*/
fid = (*env)->GetFieldID(env, cls, "uid", "J");
if (fid == 0) {
jclass newExcCls =
(*env)->FindClass(env, "java/lang/IllegalArgumentException");
if (newExcCls == 0) {
/* Unable to find the new exception class, give up. */
return;
}
(*env)->ThrowNew(env, newExcCls, "invalid field: username");
(*env)->ExceptionClear(env);
throwIllegalArgumentException(env, "invalid field: uid");
return;
}
(*env)->SetLongField(env, obj, fid, pwd.pw_uid);
@ -98,13 +98,9 @@ Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo
*/
fid = (*env)->GetFieldID(env, cls, "gid", "J");
if (fid == 0) {
jclass newExcCls =
(*env)->FindClass(env, "java/lang/IllegalArgumentException");
if (newExcCls == 0) {
/* Unable to find the new exception class, give up. */
return;
}
(*env)->ThrowNew(env, newExcCls, "invalid field: username");
(*env)->ExceptionClear(env);
throwIllegalArgumentException(env, "invalid field: gid");
return;
}
(*env)->SetLongField(env, obj, fid, pwd.pw_gid);
@ -113,17 +109,17 @@ Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo
*/
fid = (*env)->GetFieldID(env, cls, "groups", "[J");
if (fid == 0) {
jclass newExcCls =
(*env)->FindClass(env, "java/lang/IllegalArgumentException");
if (newExcCls == 0) {
/* Unable to find the new exception class, give up. */
return;
}
(*env)->ThrowNew(env, newExcCls, "invalid field: username");
(*env)->ExceptionClear(env);
throwIllegalArgumentException(env, "invalid field: groups");
return;
}
jgroups = (*env)->NewLongArray(env, numSuppGroups);
if (jgroups == NULL)
return;
jgroupsAsArray = (*env)->GetLongArrayElements(env, jgroups, 0);
if (jgroupsAsArray == NULL)
return;
for (i = 0; i < numSuppGroups; i++)
jgroupsAsArray[i] = groups[i];
(*env)->ReleaseLongArrayElements(env, jgroups, jgroupsAsArray, 0);

View File

@ -60,7 +60,7 @@ Java_com_sun_security_auth_module_UnixSystem_getUnixInfo
groups = (gid_t *)calloc(numSuppGroups, sizeof(gid_t));
if (groups == NULL) {
jclass cls = (*env)->FindClass(env,"java/lang/OutOfMemoryError");
if(cls != 0)
if (cls != NULL)
(*env)->ThrowNew(env, cls, NULL);
return;
}
@ -90,6 +90,8 @@ Java_com_sun_security_auth_module_UnixSystem_getUnixInfo
goto cleanUpAndReturn;
jstr = (*env)->NewStringUTF(env, pwd->pw_name);
if (jstr == NULL)
goto cleanUpAndReturn;
(*env)->SetObjectField(env, obj, userNameID, jstr);
(*env)->SetLongField(env, obj, userID, pwd->pw_uid);
@ -97,7 +99,11 @@ Java_com_sun_security_auth_module_UnixSystem_getUnixInfo
(*env)->SetLongField(env, obj, groupID, pwd->pw_gid);
jgroups = (*env)->NewLongArray(env, numSuppGroups);
if (jgroups == NULL)
goto cleanUpAndReturn;
jgroupsAsArray = (*env)->GetLongArrayElements(env, jgroups, 0);
if (jgroupsAsArray == NULL)
goto cleanUpAndReturn;
for (i = 0; i < numSuppGroups; i++)
jgroupsAsArray[i] = groups[i];
(*env)->ReleaseLongArrayElements(env, jgroups, jgroupsAsArray, 0);

View File

@ -43,6 +43,12 @@ BOOL getImpersonationToken(PHANDLE impersonationToken);
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) {
@ -62,7 +68,6 @@ Java_com_sun_security_auth_module_NTSystem_getCurrent
long i, j = 0;
HANDLE tokenHandle = INVALID_HANDLE_VALUE;
BOOL systemError = FALSE;
LPTSTR userName = NULL; // user name
LPTSTR userSid = NULL; // user sid
@ -116,70 +121,59 @@ Java_com_sun_security_auth_module_NTSystem_getCurrent
fid = (*env)->GetFieldID(env, cls, "userName", "Ljava/lang/String;");
if (fid == 0) {
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");
(*env)->ExceptionClear(env);
throwIllegalArgumentException(env, "invalid field: userName");
goto cleanup;
}
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) {
jclass newExcCls =
(*env)->FindClass(env, "java/lang/IllegalArgumentException");
if (newExcCls == 0) {
systemError = TRUE;
goto out;
}
(*env)->ThrowNew(env, newExcCls, "invalid field: userSID");
(*env)->ExceptionClear(env);
throwIllegalArgumentException(env, "invalid field: userSID");
goto cleanup;
}
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) {
jclass newExcCls =
(*env)->FindClass(env, "java/lang/IllegalArgumentException");
if (newExcCls == 0) {
systemError = TRUE;
goto out;
}
(*env)->ThrowNew(env, newExcCls, "invalid field: domain");
(*env)->ExceptionClear(env);
throwIllegalArgumentException(env, "invalid field: domain");
goto cleanup;
}
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) {
jclass newExcCls =
(*env)->FindClass(env, "java/lang/IllegalArgumentException");
if (newExcCls == 0) {
systemError = TRUE;
goto out;
}
(*env)->ThrowNew(env, newExcCls, "invalid field: domainSID");
(*env)->ExceptionClear(env);
throwIllegalArgumentException(env, "invalid field: domainSID");
goto cleanup;
}
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) {
jclass newExcCls =
(*env)->FindClass(env, "java/lang/IllegalArgumentException");
if (newExcCls == 0) {
systemError = TRUE;
goto out;
}
(*env)->ThrowNew(env, newExcCls, "invalid field: PrimaryGroupID");
(*env)->ExceptionClear(env);
throwIllegalArgumentException(env, "invalid field: PrimaryGroupID");
goto cleanup;
}
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
@ -204,19 +198,14 @@ Java_com_sun_security_auth_module_NTSystem_getCurrent
fid = (*env)->GetFieldID(env, cls, "groupIDs", "[Ljava/lang/String;");
if (fid == 0) {
jclass newExcCls =
(*env)->FindClass(env, "java/lang/IllegalArgumentException");
if (newExcCls == 0) {
systemError = TRUE;
goto out;
}
(*env)->ThrowNew(env, newExcCls, "invalid field: groupIDs");
(*env)->ExceptionClear(env);
throwIllegalArgumentException(env, "groupIDs");
goto cleanup;
}
stringClass = (*env)->FindClass(env, "java/lang/String");
if (stringClass == 0) {
goto out;
}
if (stringClass == NULL)
goto cleanup;
if (pIndex == -1) {
// primary group not in groups array
@ -226,6 +215,8 @@ Java_com_sun_security_auth_module_NTSystem_getCurrent
// 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) {
@ -233,12 +224,14 @@ Java_com_sun_security_auth_module_NTSystem_getCurrent
continue;
}
jstr = (*env)->NewStringUTF(env, groups[i]);
if (jstr == NULL)
goto cleanup;
(*env)->SetObjectArrayElement(env, jgroups, j++, jstr);
}
(*env)->SetObjectField(env, obj, fid, jgroups);
}
out:
cleanup:
if (userName != NULL) {
HeapFree(GetProcessHeap(), 0, userName);
}
@ -264,11 +257,6 @@ out:
}
CloseHandle(tokenHandle);
if (systemError && debug) {
printf(" [getCurrent] System Error: ");
printf("unable to find IllegalArgumentException class\n");
}
return;
}
@ -336,7 +324,7 @@ BOOL getUser(HANDLE tokenHandle, LPTSTR *userName,
DisplayErrorText(GetLastError());
}
error = TRUE;
goto out;
goto cleanup;
}
if (debug) {
@ -369,7 +357,7 @@ BOOL getUser(HANDLE tokenHandle, LPTSTR *userName,
DisplayErrorText(GetLastError());
}
error = TRUE;
goto out;
goto cleanup;
}
if (debug) {
@ -411,7 +399,7 @@ BOOL getUser(HANDLE tokenHandle, LPTSTR *userName,
DisplayErrorText(GetLastError());
}
// ok not to have a domain SID (no error)
goto out;
goto cleanup;
}
bufSize = 0;
@ -422,7 +410,7 @@ BOOL getUser(HANDLE tokenHandle, LPTSTR *userName,
printf(" [getUser] domainSid: %s\n", *domainSid);
}
out:
cleanup:
if (tokenUserInfo != NULL) {
HeapFree(GetProcessHeap(), 0, tokenUserInfo);
}
@ -466,7 +454,7 @@ BOOL getPrimaryGroup(HANDLE tokenHandle, LPTSTR *primaryGroup) {
DisplayErrorText(GetLastError());
}
error = TRUE;
goto out;
goto cleanup;
}
if (debug) {
@ -481,7 +469,7 @@ BOOL getPrimaryGroup(HANDLE tokenHandle, LPTSTR *primaryGroup) {
printf(" [getPrimaryGroup] primaryGroup: %s\n", *primaryGroup);
}
out:
cleanup:
if (tokenGroupInfo != NULL) {
HeapFree(GetProcessHeap(), 0, tokenGroupInfo);
}
@ -519,7 +507,7 @@ BOOL getGroups(HANDLE tokenHandle, PDWORD numGroups, LPTSTR **groups) {
DisplayErrorText(GetLastError());
}
error = TRUE;
goto out;
goto cleanup;
}
if (debug) {
@ -528,7 +516,7 @@ BOOL getGroups(HANDLE tokenHandle, PDWORD numGroups, LPTSTR **groups) {
if (tokenGroupInfo->GroupCount == 0) {
// no groups
goto out;
goto cleanup;
}
// return group info
@ -545,7 +533,7 @@ BOOL getGroups(HANDLE tokenHandle, PDWORD numGroups, LPTSTR **groups) {
}
}
out:
cleanup:
if (tokenGroupInfo != NULL) {
HeapFree(GetProcessHeap(), 0, tokenGroupInfo);
}