Latent memory leaks in KEM_KEY setter functions#3041
Open
Latent memory leaks in KEM_KEY setter functions#3041
Conversation
dkostic
approved these changes
Feb 24, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3041 +/- ##
=======================================
Coverage 78.35% 78.36%
=======================================
Files 689 689
Lines 121010 121014 +4
Branches 16992 16991 -1
=======================================
+ Hits 94813 94827 +14
+ Misses 25302 25292 -10
Partials 895 895 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Description of changes:
KEM_KEY_set_raw_public_key,KEM_KEY_set_raw_secret_key, andKEM_KEY_set_raw_keyoverwritekey->public_keyand/orkey->secret_keywithout first freeing any existing allocation. If these functions were ever called on aKEM_KEYthat already had key material set, the previous buffers would be leaked.KEM_KEY_new), but the functions themselves are unsafe if reused in other contexts.This change adds
OPENSSL_freecalls before each pointer is overwritten, consistent with howKEM_KEY_initalready callsKEM_KEY_clearbefore re-initializing.Call-outs:
This is a hardening fix. The added
OPENSSL_freecalls are no-ops in all current call sites (the pointers are always NULL), so there is no change in observable behavior today.Testing:
Existing tests cover these code paths. No new tests required since the fix does not alter behavior for current callers.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.