Skip to content

Use heap allocation for CSR PEM conversion on small stack builds#462

Merged
dgarske merged 1 commit intowolfSSL:masterfrom
jackctj117:CONTENT_SIZE
Feb 24, 2026
Merged

Use heap allocation for CSR PEM conversion on small stack builds#462
dgarske merged 1 commit intowolfSSL:masterfrom
jackctj117:CONTENT_SIZE

Conversation

@jackctj117
Copy link
Contributor

This pull request improves memory handling in the PEM conversion process within the TPM2 CSR generation code, particularly for environments with constrained stack space. The changes ensure that temporary buffers are dynamically allocated when needed, reducing stack usage and preventing potential buffer overflows.

Memory management improvements for PEM conversion:

  • In both CSR_MakeAndSign and CSR_MakeAndSign_Cb functions in src/tpm2_wrap.c, added conditional logic to allocate the temporary buffer on the heap using XMALLOC when WOLFTPM_SMALL_STACK is defined, and to free it with XFREE after use. This helps support devices with limited stack space. [1] [2]
  • Ensured that the size used for copying and conversion is consistently handled by introducing a derSz variable, improving code clarity and correctness. [1] [2]

Copy link

Copilot AI left a comment

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 optimizes memory usage in TPM2 CSR generation for resource-constrained environments by conditionally using heap allocation instead of stack allocation for temporary PEM conversion buffers.

Changes:

  • Added conditional compilation logic to allocate PEM conversion buffers on the heap when WOLFTPM_SMALL_STACK is defined
  • Introduced derSz variable to improve clarity when tracking DER size throughout the conversion process

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

@dgarske dgarske merged commit 960cb90 into wolfSSL:master Feb 24, 2026
72 checks passed
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.

4 participants