Skip to content

Fix test_tls13_ticket_set_alloc_fail with --enable-trackmemory - #12063

Open
ohki-saito wants to merge 1 commit into
wolfSSL:masterfrom
ohki-saito:fix/allocater
Open

ohki-saito wants to merge 1 commit into
wolfSSL:masterfrom
ohki-saito:fix/allocater

Conversation

@ohki-saito

Copy link
Copy Markdown
Contributor

Description

Non-Fenrir findings

test_tls13_ticket_set_alloc_fail aborts with --enable-trackmemory because its allocators call raw malloc/free, while the ticket buffer was allocated by TrackMalloc before the swap. Delegate to the saved allocators instead, as done for the PKCS12 and OCSP OOM tests.

Other tests also call raw malloc/free in their allocators, but they don’t fail with --enable-trackmemory today.

Testing

make check with --enable-all --enable-trackmemory.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

Copilot AI balanced review requested due to automatic review settings November 9, 2026 07:31

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.

Note

Copilot was unable to run its full agentic suite in this review.

Copilot review overview

4 open issues
What changed in this PR

Adjusts the TLS 1.3 session ticket allocation-failure test to wrap the “real” allocators (the ones installed before the test) so allocations can be cleaned up correctly after allocator restoration.

Changes:

  • Store the pre-test allocator callbacks in file-scope statics and route allocations/frees through them.
  • Update the failure-injection malloc/free/realloc wrappers to call the previous callbacks when present.
  • Replace per-test local “prev allocator” variables with the new statics.
File Description
tests/​api/​test_tls13.c Routes test allocation wrappers through previously installed allocators and updates the test to restore allocator state using saved callbacks.

Review effort: Lite

Comment thread tests/api/test_tls13.c
Comment on lines +13155 to +13156
return (ticket_alloc_prev_malloc != NULL) ?
ticket_alloc_prev_malloc(size) : malloc(size);
Comment thread tests/api/test_tls13.c
Comment on lines +13161 to +13164
if (ticket_alloc_prev_free != NULL)
ticket_alloc_prev_free(ptr);
else
free(ptr);
Comment thread tests/api/test_tls13.c
Comment on lines +13169 to +13170
return (ticket_alloc_prev_realloc != NULL) ?
ticket_alloc_prev_realloc(ptr, size) : realloc(ptr, size);
Comment thread tests/api/test_tls13.c
Comment on lines 13220 to 13233
ExpectIntEQ(wolfSSL_send_SessionTicket(ssl_s), WOLFSSL_SUCCESS);
if (EXPECT_SUCCESS()) {
ticket_alloc_fail_sz = ssl_c->session->ticketLen;
ExpectIntEQ(wolfSSL_GetAllocators(&prevM, &prevF, &prevR), 0);
ExpectIntEQ(wolfSSL_GetAllocators(&ticket_alloc_prev_malloc,
&ticket_alloc_prev_free, &ticket_alloc_prev_realloc), 0);
ExpectIntEQ(wolfSSL_SetAllocators(ticket_alloc_fail_malloc,
ticket_alloc_fail_free, ticket_alloc_fail_realloc), 0);
ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1);
ticket_alloc_fail_sz = 0;
(void)wolfSSL_SetAllocators(prevM, prevF, prevR);
(void)wolfSSL_SetAllocators(ticket_alloc_prev_malloc,
ticket_alloc_prev_free, ticket_alloc_prev_realloc);
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1),
WC_NO_ERR_TRACE(MEMORY_E));
}
@ohki-saito

Copy link
Copy Markdown
Contributor Author

I don't think a change is needed, for the following reason

wolfSSL_Malloc/Free/Realloc in memory.c also fall back to the standard functions per callback when one is NULL, and these callbacks do the same, so the pairing of allocations and frees doesn’t change. If the callbacks were only partly set, wolfSSL itself would already break: with SetAllocators(TrackMalloc, NULL, TrackRealloc), the test aborts in wolfSSL_send_SessionTicket before these callbacks are installed. Requiring all three to be non-NULL would also stop the test from running in the default build, where they are all NULL.

ExpectIntEQ() doesn’t change control flow; after a failure it only skips evaluating later Expect checks. The reset of ticket_alloc_fail_sz and the allocator restore are plain statements, so they run on every path, and GetAllocators() always runs because the block is only entered on success. The structure is unchanged from master.

@ohki-saito
ohki-saito marked this pull request as ready for review November 10, 2026 07:27
@github-actions

Copy link
Copy Markdown

retest this please

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m0plus

  • FLASH: .text +24 B (+0.0%, 70,827 B / 262,144 B, total: 27% used)

gcc-arm-cortex-m3

  • FLASH: .text +20 B (+0.0%, 131,781 B / 262,144 B, total: 50% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +640 B (+0.1%, 801,508 B / 1,048,576 B, total: 76% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 209,100 B / 262,144 B, total: 80% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata -8 B, text +3,688 B (+1.3%, 286,152 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

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