fix: reset ret after EccVerify pubkey export fail#441
Open
MarkAtwood wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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 = 0whenwc_EccPublicKeyToDer()returns an error during the optional pubkey export path, while settingpub_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 setspub_size = 0but does not resetret, soretkeeps the negative DER error code:At
cleanup:, the response is only written underif (ret == 0). Withretstill negative, the successful verify result (res.res) is never written,*outSizeis 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 = 0in the error branch, matching the stated intent of the comment ("Set to 0 length" implies continue) and the symmetric success branch, which already doesret = 0:The verify result is then returned with a zero-length pubkey, as intended.
Verification
Built
wh_server_crypto.cagainst 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).