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

[CRYPTO-169][FOLLOWUP] Fix reentrancy of CryptoRandomFactory#getCryptoRandom #259

Merged
merged 7 commits into from
Oct 23, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
java 8 and 11
LuciferYang committed Oct 22, 2023

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
commit 69adb018951d476fb39a4cc2745c5d4790ad02ae
Original file line number Diff line number Diff line change
@@ -208,9 +208,13 @@ public static CryptoRandom getCryptoRandom(final Properties props)
}
} catch (final NoClassDefFoundError noClassDefFoundError) {
Throwable initializerError = noClassDefFoundError.getCause();
Copy link
Contributor Author

@LuciferYang LuciferYang Oct 22, 2023

Choose a reason for hiding this comment

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

There are some differences here between Java 8/11 and Java 17/21:

  • Java 8/11: Will catch NoClassDefFoundError, but NoClassDefFoundError.getCause is null.
  • Java 17/21: Will catch NoClassDefFoundError, and NoClassDefFoundError.getCause is ExceptionInInitializerError, but ExceptionInInitializerError.getCause is null

So the check way here is a bit tricky, do you have any better suggestions? @garydgregory

Copy link
Member

Choose a reason for hiding this comment

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

@LuciferYang
Not off the top of my head...

String message = noClassDefFoundError.getMessage();
if (initializerError instanceof ExceptionInInitializerError) {
lastException = new IllegalStateException(initializerError.getMessage());
lastException = new IllegalStateException(initializerError.getMessage());
errorMessage.append("CryptoRandom: [" + className + "] initialization failed with " + initializerError.getMessage());
} else if (initializerError == null && message != null && message.startsWith("Could not initialize class")) {
lastException = new IllegalStateException(message);
errorMessage.append("CryptoRandom: [" + className + "] initialization failed with " + message);
} else {
throw noClassDefFoundError;
}