fixed error handling in crypto setup - #282
Conversation
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #282
Scan targets checked: wolfclu-bugs, wolfclu-src
Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
afb0fdd to
4da2df3
Compare
There was a problem hiding this comment.
Pull request overview
This pull request refactors wolfCLU_setup() error handling in the crypto CLI to avoid early returns and instead funnel execution to a shared cleanup path, while also tightening argument validation around explicit key/IV usage. It also updates the encryption regression test to use the CLI’s -key/-iv flags.
Changes:
- Refactor
wolfCLU_setup()control flow to gate parsing/execution onretand always reach common cleanup. - Add/adjust validation ordering for incompatible/missing flag combinations (e.g.,
-keyrequires-iv). - Update encryption regression test to pass
-key/-iv(matching the crypto option table/help text).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/encrypt/enc-test.py | Updates regression test to use -key/-iv arguments for explicit hex key/IV. |
| src/crypto/clu_crypto_setup.c | Refactors setup error handling to converge on shared cleanup and adds early validation for invalid flag combinations. |
Suppressed comments (3)
src/crypto/clu_crypto_setup.c:401
- On wolfCLU_hexToBin failure, ret is unconditionally replaced with WOLFCLU_FATAL_ERROR. This drops MEMORY_E (OOM) and conflicts with the earlier contract in this file to propagate MEMORY_E unchanged. Preserve MEMORY_E and only map non-OOM failures to WOLFCLU_FATAL_ERROR.
if (ret != WOLFCLU_SUCCESS) {
WOLFCLU_LOG(WOLFCLU_E0,
"failed during conversion of IV, ret = %d", ret);
ret = WOLFCLU_FATAL_ERROR;
break;
src/crypto/clu_crypto_setup.c:494
- If allocating fileBuf fails when handling -inkey, ret is set to WOLFCLU_FATAL_ERROR. To keep error handling consistent with the rest of this function (and avoid masking OOM), set ret to MEMORY_E on allocation failure.
if (fileBuf == NULL) {
wolfSSL_BIO_free(keyBio);
ret = WOLFCLU_FATAL_ERROR;
break;
}
src/crypto/clu_crypto_setup.c:533
- If allocating keyString fails when parsing a hex -inkey file, ret is set to WOLFCLU_FATAL_ERROR, which masks out-of-memory as a generic failure. Set ret to MEMORY_E here to preserve allocation failure semantics.
if (keyString == NULL) {
wolfCLU_ForceZero(fileBuf, fileLen);
XFREE(fileBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
ret = WOLFCLU_FATAL_ERROR;
break;
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
In stead of early returns I changed the control flow to reach the common clean up at the bottom of the set up function. This behavior change starts after the GetOpt loop because the common clean up assumes that the code above the GetOpt loop has run
Started with fix for this Fenrir issue https://fenrir.wolfssl.com/finding/8061 and in addition I changed the error handling to be in line with the rest of the code base