sha512: free SHA-512/384 W cache with its allocated memory type#10776
Open
julek-wolfssl wants to merge 1 commit into
Open
sha512: free SHA-512/384 W cache with its allocated memory type#10776julek-wolfssl wants to merge 1 commit into
julek-wolfssl wants to merge 1 commit into
Conversation
With WOLFSSL_SMALL_STACK_CACHE, wc_Sha512Free and wc_Sha384Free freed the cached W buffer as DYNAMIC_TYPE_TMP_BUFFER, but it is allocated as DYNAMIC_TYPE_DIGEST in InitSha512_Family/InitSha384 and the Copy functions (the in-Init error cleanup already frees it as DYNAMIC_TYPE_DIGEST). The mismatch is flagged by the memusage test (DHE_RSA TLS1.2 reports Errors: 2) and matters for type-bucketed static memory pools. SHA-256/224 already use DYNAMIC_TYPE_DIGEST consistently. Free W as DYNAMIC_TYPE_DIGEST.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a memory-type mismatch in the SHA-512/SHA-384 “small stack cache” (WOLFSSL_SMALL_STACK_CACHE) by freeing the cached W buffer using the same allocation type it was allocated with (DYNAMIC_TYPE_DIGEST). This matters for type-bucketed/static memory pool allocators where free must match the allocation bucket.
Changes:
- Update
wc_Sha512Free()to freesha512->WasDYNAMIC_TYPE_DIGEST(matchingInitSha512_Family()/ copy allocation). - Update
wc_Sha384Free()to freesha384->WasDYNAMIC_TYPE_DIGEST(matchingInitSha384()/ copy allocation).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
With
WOLFSSL_SMALL_STACK_CACHE,wc_Sha512Freeandwc_Sha384Freefreed thecached
Wbuffer asDYNAMIC_TYPE_TMP_BUFFER, but it is allocated asDYNAMIC_TYPE_DIGESTinInitSha512_Family/InitSha384and in theCopyfunctions (the in-
Initerror-cleanup path already frees it asDYNAMIC_TYPE_DIGEST).This mismatch is harmless for a plain heap, but it matters for type-bucketed
static memory pools, where allocation and free must use the same memory type.
SHA-256/224 already use
DYNAMIC_TYPE_DIGESTconsistently.Free
WasDYNAMIC_TYPE_DIGESTin both free functions.Testing
The mismatch is flagged by the memusage test (DHE_RSA TLS1.2 reported
Errors: 2); with this fix the count returns to 0.