Release cipher_data on error path too for EVP_CTRL_INIT and EVP_CTRL_COPY#3243
Merged
torben-hansen merged 2 commits intoMay 13, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3243 +/- ##
==========================================
- Coverage 78.36% 78.15% -0.22%
==========================================
Files 689 689
Lines 123265 123291 +26
Branches 17143 17143
==========================================
- Hits 96602 96354 -248
- Misses 25752 26025 +273
- Partials 911 912 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
justsmth
reviewed
May 12, 2026
Comment on lines
+1410
to
+1430
| // Mock cipher whose |EVP_CTRL_INIT| handler always fails. It's needed to | ||
| // exercise the error paths in |EVP_CipherInit_ex| and |EVP_CIPHER_CTX_copy|. | ||
| // In addition, the mock needs |ctx_size| != 0, otherwise |cipher_data| is | ||
| // not allocated before the ctrl callback runs. This is needed below for | ||
| // InitErrorPathReleasesCipherData, to test |cipher_data| is free'd. | ||
| static int mock_failing_init(EVP_CIPHER_CTX *, const uint8_t *, const uint8_t *, | ||
| int) { | ||
| return 1; | ||
| } | ||
|
|
||
| static int mock_failing_cipher(EVP_CIPHER_CTX *, uint8_t *, const uint8_t *, | ||
| size_t) { | ||
| return 1; | ||
| } | ||
|
|
||
| static int mock_failing_ctrl(EVP_CIPHER_CTX *, int type, int, void *) { | ||
| if (type == EVP_CTRL_INIT) { | ||
| return 0; | ||
| } | ||
| return -1; | ||
| } |
Contributor
There was a problem hiding this comment.
Returning 1 means SUCCESS, not failure:
// Mock ciphers used to exercise the error paths in |EVP_CipherInit_ex| and
// |EVP_CIPHER_CTX_copy|. The mocks need |ctx_size| != 0, otherwise
// |cipher_data| is not allocated before the ctrl callback runs, which is
// what |InitErrorPathReleasesCipherData| and |CopyErrorPathReleasesCipherData|
// test is free'd on the error path.
static int mock_noop_init(EVP_CIPHER_CTX *, const uint8_t *, const uint8_t *,
int) {
return 1;
}
static int mock_noop_cipher(EVP_CIPHER_CTX *, uint8_t *, const uint8_t *,
size_t) {
return 1;
}
static int mock_failing_init_ctrl(EVP_CIPHER_CTX *, int type, int, void *) {
if (type == EVP_CTRL_INIT) {
return 0;
}
return -1;
}
Contributor
Author
There was a problem hiding this comment.
Right. The namespace is used for mocking a failing cipher operation not for the each individual cipher. So, on the side of not changing name.
9a36059 to
3317fc4
Compare
samuel40791765
approved these changes
May 12, 2026
prasden
approved these changes
May 12, 2026
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:
On the error-path, which I don't think is actually reachable right now,
cipher_datashould be released, otherwise it would/can leak. It's not exactly likely a context would ever be re-used in the error case, but who knows. It doesn't cost anything to gate it.Testing:
Two tests, exercising the error path and test new assertion.
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.