Skip to content

fixed error handling in crypto setup - #282

Merged
JacobBarthelmeh merged 1 commit into
wolfSSL:mainfrom
aidankeefe2022:fenrir-8061
Aug 12, 2026
Merged

fixed error handling in crypto setup#282
JacobBarthelmeh merged 1 commit into
wolfSSL:mainfrom
aidankeefe2022:fenrir-8061

Conversation

@aidankeefe2022

Copy link
Copy Markdown
Member

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

@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 #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.

Comment thread src/crypto/clu_crypto_setup.c Outdated
Comment thread src/crypto/clu_crypto_setup.c

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.

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 on ret and always reach common cleanup.
  • Add/adjust validation ordering for incompatible/missing flag combinations (e.g., -key requires -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.

Comment thread src/crypto/clu_crypto_setup.c
@JacobBarthelmeh
JacobBarthelmeh merged commit d23690b into wolfSSL:main Aug 12, 2026
17 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.

5 participants