Repository navigation
Harden the argument checks in three wolfCrypt APIs - #12031
yosuke-wolfssl wants to merge 3 commits into
Conversation
- wolfAsync_DevOpenThread() returns BAD_FUNC_ARG when pDevId is NULL, before opening a device. - It writes the computed device ID to *pDevId unconditionally. Issue: F-9928
- wc_AsyncThreadCreate_ex() returns BAD_FUNC_ARG for a NULL thread or function before initializing the pthread attributes. Issue: F-12969
- wc_SHE_ExportKey() returns BAD_FUNC_ARG when a non-NULL M1-M5 buffer is smaller than WC_SHE_M1_SZ through WC_SHE_M5_SZ. - The EN and JA dox blocks list the new BAD_FUNC_ARG case. - tests/api: short M1-M5 sizes are rejected; NULL buffers are accepted. Issue: F-12964
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the argument-validation changes.
No open issues 🎉
What changed in this PR
This PR hardens argument validation in three public wolfCrypt APIs while preserving the documented behavior that NULL SHE output buffers skip their messages.
Changes:
- Reject NULL arguments in the async device/thread APIs and always write the device ID when
pDevIdis valid. - Reject undersized non-NULL SHE export buffers, with regression tests for M1–M5 and all-NULL outputs.
- Update English and Japanese API documentation for the new SHE error condition.
| File | Description |
|---|---|
wolfcrypt/src/wc_she.c |
Validate SHE export buffer sizes. |
wolfcrypt/src/async.c |
Add NULL checks and make device-ID assignment unconditional. |
tests/api/test_she.c |
Test undersized buffers and accepted NULL outputs. |
doc/dox_comments/header_files/wc_she.h |
Document the buffer-size error in English. |
doc/dox_comments/header_files-ja/wc_she.h |
Document the buffer-size error in Japanese. |
Review effort: Balanced
|
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12031
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files-ja/wc_she.h, doc/dox_comments/header_files/wc_she.h
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max
Problem
Three public wolfCrypt APIs lack some of argument checks:
wolfAsync_DevOpenThread()wc_AsyncThreadCreate_ex()wc_SHE_ExportKey()Fix (
wolfcrypt/src/async.c,wolfcrypt/src/wc_she.c)wolfAsync_DevOpenThread()returnsBAD_FUNC_ARGfor a NULLpDevIdbefore opening any device, and always writes the device ID.wc_AsyncThreadCreate_ex()returnsBAD_FUNC_ARGfor a NULLthreadorfunction, beforepthread_attr_init().wc_SHE_ExportKey()returnsBAD_FUNC_ARGwhen a non-NULL Mn buffer is smaller thanWC_SHE_Mn_SZ. The EN and JA doxygen list the new case.NULL SHE buffers are still accepted, although f-12964 recommends rejecting them. The header and doxygen document NULL as "skip that message", and both in-tree test callbacks rely on it.
Closes f-9928, f-12969 and f-12964.
Tests
test_wc_SHE_CryptoCbchecks each of M1-M5 one byte short (BAD_FUNC_ARG) and an all-NULL call (succeeds). The async changes have no new tests: they only add NULL checks, and the conditional write can only be reached with Cavium/QAT hardware.Verification
--enable-asynccrypt --enable-cryptocb --enable-debug,--enable-she=extended --enable-cryptocb --enable-debug, and with-DNO_WC_SHE_EXPORTKEY.testwolfcryptpasses on the async build; SHE API group 14/14 passes.m2SzagainstWC_SHE_M1_SZ, or dropping amN != NULLguard each failstest_wc_SHE_CryptoCb.