Skip to content

Store an alt name with its entry in one allocation - #11342

Open
Frauschi wants to merge 1 commit into
wolfSSL:masterfrom
Frauschi:tls_mem_5
Open

Store an alt name with its entry in one allocation#11342
Frauschi wants to merge 1 commit into
wolfSSL:masterfrom
Frauschi:tls_mem_5

Conversation

@Frauschi

@Frauschi Frauschi commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

One of six independent branches that cut allocations in the TLS and certificate layers. Self-contained and touches no TLS code.

What changes

Parsing the subject alternative names of a certificate allocated a DNS_entry and then a second buffer for the name it points at - a shape the code itself flagged with a "consider one malloc" note. A chain carrying six names cost twelve allocations on every handshake that verifies it.

AltNameNewEx() allocates the entry with room for the name behind it and copies the name in, so a six name chain costs six allocations. wolfSSL_X509_add_altname_ex() uses the same helper.

The failure path in SetDNSEntry() now hands the entry to FreeAltNames() instead of freeing two buffers by hand, so any ipString or ridString a later step allocates is released with it. Nothing leaked before this - no in-tree path can fail after those buffers are built - it is hardening against a future failure path.

API note

An entry built this way reports nameStored == 0, which parsing already used for a name borrowed from the input DER. Either way the name is not a separate allocation and must not be freed on its own. Application code that walks WOLFSSL_X509->altNames or DecodedCert->altNames and frees name only when nameStored is set is unaffected; code that frees it unconditionally was already wrong.

AltNameNewEx() rejects a negative length, and a NULL name with a positive length, rather than leaving len covering bytes that were never written - which the old inline code did. SetDNSEntry() screens those arguments before allocating so a NULL return really does mean out of memory, rather than reporting a bad argument as MEMORY_E and sending a caller that retries on MEMORY_E round forever. wolfSSL_X509_add_altname_ex() bounds its word32 length against INT_MAX explicitly rather than relying on what an out-of-range value narrows to.

Parsing the subject alternative names of a certificate allocated a DNS_entry
and then a second buffer for the name it points at, which the code itself
flagged with a "consider one malloc" note. A chain carrying six names cost
twelve allocations on every handshake that verifies it.

AltNameNewEx() allocates the entry with room for the name behind it and copies
the name in, leaving nameStored at 0 so FreeAltNames() does not try to release
it separately. The failure path in SetDNSEntry() now hands the entry to
FreeAltNames() rather than freeing the two buffers by hand, which also releases
the ipString and ridString a partly built entry may already hold.
@Frauschi Frauschi self-assigned this Sep 1, 2026

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #11342

Scan targets checked: wolfcrypt-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m0plus

  • FLASH: .text +44 B (+0.1%, 66,927 B / 262,144 B, total: 26% used)

gcc-arm-cortex-m3

  • FLASH: .text +32 B (+0.0%, 125,699 B / 262,144 B, total: 48% used)

gcc-arm-cortex-m4-crypto-only

  • FLASH: .text +64 B (+0.0%, 178,026 B / 262,144 B, total: 68% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +64 B (+0.0%, 186,300 B / 1,048,576 B, total: 18% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +64 B (+0.0%, 301,084 B / 1,048,576 B, total: 29% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +64 B (+0.0%, 241,697 B / 262,144 B, total: 92% used)

linuxkm-pie

  • Data: __patchable_function_entries +8 B (+0.0%, 26,856 B)

linuxkm-standard

@Frauschi

Frauschi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Jenkins retest this please - history lost.

@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi Sep 2, 2026
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.

3 participants