Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8341792: Fix ExceptionOccurred in java.security.jgss #21424

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright year is not updated

Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ void _SCDynamicStoreCallBack(SCDynamicStoreRef store, CFArrayRef changedKeys, vo
jmethodID jm_Config_refresh = (*env)->GetStaticMethodID(env, jc_Config, "refresh", "()V");
CHECK_NULL(jm_Config_refresh);
(*env)->CallStaticVoidMethod(env, jc_Config, jm_Config_refresh);
if ((*env)->ExceptionOccurred(env) != NULL) {
Copy link
Member

@justin-curtis-lu justin-curtis-lu Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can keep the original behavior if you want to, because its being compared to NULL and not as a boolean.

Returns the exception object that is currently in the process of being thrown, or NULL if no exception is currently being thrown.

But the new code might read better. So I guess it is just preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One concern pointed out by the umbrella bug is that ExceptionOccured(env) returns a jthrowable reference that should be freed by DeleteLocalRef(jthrowable). Even if the reference could be automatically freed later, it's probably still a good practice to either free them early or just not create them at all.

if ((*env)->ExceptionCheck(env)) {
(*env)->ExceptionClear(env);
}
if (createdFromAttach) {
Original file line number Diff line number Diff line change
@@ -877,13 +877,13 @@ jobject BuildTicket(JNIEnv *env, PUCHAR encodedTicket, ULONG encodedTicketSize)

(*env)->SetByteArrayRegion(env, ary, (jsize) 0, encodedTicketSize,
(jbyte *)encodedTicket);
if ((*env)->ExceptionOccurred(env)) {
if ((*env)->ExceptionCheck(env)) {
(*env)->DeleteLocalRef(env, ary);
return (jobject) NULL;
}

ticket = (*env)->NewObject(env, ticketClass, ticketConstructor, ary);
if ((*env)->ExceptionOccurred(env)) {
if ((*env)->ExceptionCheck(env)) {
(*env)->DeleteLocalRef(env, ary);
return (jobject) NULL;
}
@@ -993,7 +993,7 @@ jobject BuildEncryptionKey(JNIEnv *env, PKERB_CRYPTO_KEY cryptoKey) {
}
(*env)->SetByteArrayRegion(env, ary, (jsize) 0, cryptoKey->Length,
(jbyte *)cryptoKey->Value);
if ((*env)->ExceptionOccurred(env)) {
if ((*env)->ExceptionCheck(env)) {
(*env)->DeleteLocalRef(env, ary);
} else {
encryptionKey = (*env)->NewObject(env, encryptionKeyClass,
@@ -1018,7 +1018,7 @@ jobject BuildTicketFlags(JNIEnv *env, PULONG flags) {
}
(*env)->SetByteArrayRegion(env, ary, (jsize) 0, sizeof(*flags),
(jbyte *)&nlflags);
if ((*env)->ExceptionOccurred(env)) {
if ((*env)->ExceptionCheck(env)) {
(*env)->DeleteLocalRef(env, ary);
} else {
ticketFlags = (*env)->NewObject(env, ticketFlagsClass,