Skip to content

sha512: free SHA-512/384 W cache with its allocated memory type#10776

Open
julek-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
julek-wolfssl:fix-sha512-w-cache-free-type
Open

sha512: free SHA-512/384 W cache with its allocated memory type#10776
julek-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
julek-wolfssl:fix-sha512-w-cache-free-type

Conversation

@julek-wolfssl

Copy link
Copy Markdown
Member

Description

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 in the Copy
functions (the in-Init error-cleanup path already frees it as
DYNAMIC_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_DIGEST consistently.

Free W as DYNAMIC_TYPE_DIGEST in 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.

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.
Copilot AI review requested due to automatic review settings June 25, 2026 09:37
@julek-wolfssl julek-wolfssl self-assigned this Jun 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 free sha512->W as DYNAMIC_TYPE_DIGEST (matching InitSha512_Family() / copy allocation).
  • Update wc_Sha384Free() to free sha384->W as DYNAMIC_TYPE_DIGEST (matching InitSha384() / copy allocation).

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

@julek-wolfssl julek-wolfssl marked this pull request as ready for review June 25, 2026 14:44
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.

2 participants