Skip to content

PkCtx double free fix#377

Merged
cconlon merged 1 commit into
wolfSSL:masterfrom
stenslae:fix/pkctx-double-free
Jul 10, 2026
Merged

PkCtx double free fix#377
cconlon merged 1 commit into
wolfSSL:masterfrom
stenslae:fix/pkctx-double-free

Conversation

@stenslae

@stenslae stenslae commented Jul 10, 2026

Copy link
Copy Markdown
Member

Issue #375 -- Reordered each setter to build the new internCtx fully, install it via wolfSSL_Set*Ctx(), and only then free the old one. Deduplicated the six setters and the freeSSL cleanup blocks into two helpers, setPkCtxHelper() and freePkCtx().

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #377

Scan targets checked: wolfssljni-bugs, wolfssljni-src

No new issues found in the changed files. ✅

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses Issue #375 by eliminating a double-free / dangling-pointer hazard in the public-key callback context setters for WolfSSLSession by swapping in a fully-initialized replacement context before freeing the prior one.

Changes:

  • Introduces setPkCtxHelper() to atomically replace PK callback internCtx pointers (install new first, then free old).
  • Introduces freePkCtx() and refactors freeSSL() PK-context cleanup to use it.
  • Ensures NewGlobalRef() failure paths free the newly-allocated (but uninstalled) internCtx.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread native/com_wolfssl_WolfSSLSession.c
@stenslae stenslae force-pushed the fix/pkctx-double-free branch from 11cc041 to 44f4c55 Compare July 10, 2026 17:28

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #377

Scan targets checked: wolfssljni-bugs, wolfssljni-src

No new issues found in the changed files. ✅

@cconlon

cconlon commented Jul 10, 2026

Copy link
Copy Markdown
Member

@stenslae please rebase on master, which should pick up the fix needed for the Android Gradle test to pass, thanks.

@stenslae stenslae force-pushed the fix/pkctx-double-free branch from 44f4c55 to a4e8408 Compare July 10, 2026 19:02
@cconlon cconlon assigned cconlon and unassigned wolfSSL-Bot and stenslae Jul 10, 2026
@cconlon cconlon merged commit 3daad9e into wolfSSL:master Jul 10, 2026
106 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants