Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The reassignment test checks only replacement-cache sizes, so it can still pass when outgoing DSA/DH buffers are not wiped or freed, leaving the intended regression undetected.
1 open issue
What changed in this PR
This PR addresses F-8331 by clearing previous DER key caches during reassignment in wolfSSL’s OpenSSL compatibility layer.
Changes:
- Wipe and free cached DER data and reset cache metadata before DSA, DH, and RSA reassignment.
- Clear temporary DER buffers before release on affected paths.
- Add and register a regression test covering repeated and cross-key-type reassignment.
| File | Description |
|---|---|
wolfcrypt/src/evp.c |
Adds DER cache cleanup and temporary-buffer wiping. |
tests/api/test_evp_pkey.h |
Declares and registers the reassignment test. |
tests/api/test_evp_pkey.c |
Adds reassignment checks for DSA, RSA, and DH caches. |
Review effort: Balanced
|
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11965
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_evp_pkey.h
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max
| DER_WATCH_BEGIN(pkey); | ||
| ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsaEmpty), WOLFSSL_SUCCESS); | ||
| DER_WATCH_END(); | ||
| if (EXPECT_FAIL()) { |
There was a problem hiding this comment.
Double free of rsaEmpty when the DER watch assertion after assign_RSA fails · Incorrect error handling
DER_WATCH_END() runs between the successful EVP_PKEY_assign_RSA(pkey, rsaEmpty) and the EXPECT_FAIL() check. A failed watch assertion (the regression this test exists to catch) frees rsaEmpty while pkey owns it with ownRsa=1, and EVP_PKEY_free(pkey) at line 1212 frees it again.
Suggested fix: Put the if (EXPECT_FAIL()) RSA_free(rsaEmpty); check right after the EVP_PKEY_assign_RSA call and before DER_WATCH_END(), as the rsa block at line 1172 does.
Basis: OpenSSL EVP_PKEY_set1_RSA(3): EVP_PKEY_assign_RSA() uses the supplied key internally, so the key is freed when the parent pkey is freed.
There was a problem hiding this comment.
Thanks, fixed. The EXPECT_FAIL() ownership check now runs right after
EVP_PKEY_assign_RSA() and before DER_WATCH_END(), matching the rsa block.
Verified with ASan by forcing the watch assertion to fail at that point:
the old order hits heap-use-after-free on EVP_PKEY_free(); the new order
reports a plain test failure.

Description
Wipe and free previous EVP_PKEY DER cache on reassignment.
Fixes F-8331
Testing
Added test_wolfSSL_EVP_PKEY_reassign_der_cache.
Checklist