Skip to content

fix: reset ret after EccVerify pubkey export fail#441

Open
MarkAtwood wants to merge 1 commit into
wolfSSL:mainfrom
MarkAtwood:fix/ecc-verify-pubkey-der-ret
Open

fix: reset ret after EccVerify pubkey export fail#441
MarkAtwood wants to merge 1 commit into
wolfSSL:mainfrom
MarkAtwood:fix/ecc-verify-pubkey-der-ret

Conversation

@MarkAtwood

Copy link
Copy Markdown

Bug

In _HandleEccVerify (src/wh_server_crypto.c), when the optional public-key export path runs after a successful ECDSA verification, wc_EccPublicKeyToDer() can return a negative error (e.g. the output buffer is too small). The error branch sets pub_size = 0 but does not reset ret, so ret keeps the negative DER error code:

if (ret < 0) {
    /* Problem dumping the public key.  Set to 0 length */
    pub_size = 0;
}

At cleanup:, the response is only written under if (ret == 0). With ret still negative, the successful verify result (res.res) is never written, *outSize is left unset, and the function returns the negative error. Net effect: a successful ECDSA verify is reported to the client as a transport failure whenever the pubkey-export buffer is too small.

Fix

Reset ret = 0 in the error branch, matching the stated intent of the comment ("Set to 0 length" implies continue) and the symmetric success branch, which already does ret = 0:

if (ret < 0) {
    /* Problem dumping the public key.  Set to 0 length */
    pub_size = 0;
    ret      = 0;
}

The verify result is then returned with a zero-length pubkey, as intended.

Verification

Built wh_server_crypto.c against an installed wolfSSL (HAVE_ECC) with the test Makefile's -std=c90 -Werror -Wall -Wextra; the TU compiles clean with the fix applied.

Reported by static analysis (Fenrir finding 154).

Copilot AI review requested due to automatic review settings July 9, 2026 23:30

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

Fixes _HandleEccVerify so a successful ECDSA verify isn’t accidentally turned into an error return when optional public-key DER export fails (e.g., due to an undersized output buffer). This ensures the verify result and outSize are still produced even if the pubkey export path can’t populate the optional public key.

Changes:

  • Reset ret = 0 when wc_EccPublicKeyToDer() returns an error during the optional pubkey export path, while setting pub_size = 0.
  • Preserve successful verify behavior by allowing the response-writing block at cleanup: (if (ret == 0)) to execute.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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