JNI reference, resource, and error-handling fixes - #408
Open
cconlon wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens JNI/native resource lifetime management in wolfssljni by ensuring references, mutexes, and cryptographic key structures are properly initialized and released on both success and rollback/error paths.
Changes:
- Ensure
getSession()“owned” session references are released viatry/finallyinsetSessTimeout()andsessionToDer(). - Add mutex init result checks in
newSSL()and perform orderly cleanup of already-initialized resources on failure paths. - Prevent JNI local reference accumulation in
NativeVerifyCallbackby explicitly deleting local refs each invocation. - Validate ECC/RSA key init results before use/free to avoid operating on uninitialized structures.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/java/com/wolfssl/WolfSSLSession.java | Uses try/finally to always release getSession()-owned references in updated call sites. |
| native/com_wolfssl_WolfSSLSession.c | Checks mutex init return values and frees mutexes/resources on rollback paths in newSSL(). |
| native/com_wolfssl_WolfSSLContext.c | Adds helper to delete JNI local refs created during NativeVerifyCallback to prevent local-ref buildup. |
| native/com_wolfssl_WolfCryptRSA.c | Checks wc_InitRsaKey() result before decode/verify/decrypt logic runs. |
| native/com_wolfssl_WolfCryptECC.c | Checks wc_ecc_init() result before importing/verifying with the ECC key. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR includes 4 Fenrir fixes:
NativeVerifyCallbackdeletes the JNI local references it creates each invocation, so they no longer accumulate across a certificate chain.newSSL()checks each mutex init result and frees initialized mutexes on its construction rollback paths.sessionToDer()andsetSessTimeout()release the ownedgetSession()reference via try/finally.