Skip to content

Add sanity checks in key export#9823

Merged
JacobBarthelmeh merged 4 commits intowolfSSL:masterfrom
embhorn:zd21242
Feb 25, 2026
Merged

Add sanity checks in key export#9823
JacobBarthelmeh merged 4 commits intowolfSSL:masterfrom
embhorn:zd21242

Conversation

@embhorn
Copy link
Member

@embhorn embhorn commented Feb 24, 2026

Description

Resolve a casting overflow condition in

  1. src/ssl.c — TLS 1.2 path (line 5731)

Added a bounds check on contextLen before the seedLen calculation.

  1. src/tls13.c — TLS 1.3 path (line 1027)

Added a bounds check on contextLen against UINT32_MAX

Fixes zd21242

Testing

Added test case to test_export_keying_material_cb

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@embhorn embhorn self-assigned this Feb 24, 2026
Copilot AI review requested due to automatic review settings February 24, 2026 13:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds sanity checks to prevent integer overflow in key export functions by validating contextLen before casting operations.

Changes:

  • Added bounds check for contextLen in TLS 1.2 key export to prevent overflow in seedLen calculation
  • Added bounds check for contextLen in TLS 1.3 key export to prevent truncation when casting to word32
  • Added test case to verify rejection of contextLen values exceeding UINT16_MAX

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/ssl.c Added validation to reject contextLen > UINT16_MAX in TLS 1.2 path to prevent overflow
src/tls13.c Added validation to reject contextLen > UINT32_MAX in TLS 1.3 path to prevent truncation
tests/api.c Added test case verifying rejection of oversized contextLen values
Comments suppressed due to low confidence (1)

tests/api.c:1

  • The test verifies that the function returns 0 (failure) for oversized contextLen, but there's no test coverage for the TLS 1.3 path which uses UINT32_MAX as the limit. Consider adding a test case that exercises the TLS 1.3 code path with contextLen exceeding UINT32_MAX to ensure both validation paths are covered.

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

@embhorn embhorn assigned wolfSSL-Bot and unassigned embhorn Feb 24, 2026
dgarske
dgarske previously approved these changes Feb 24, 2026
Copilot AI review requested due to automatic review settings February 25, 2026 15:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

tests/api.c:1

  • The new test case claims contextLen values exceeding UINT16_MAX must be rejected, but it currently asserts success (... , 0). This makes the test contradictory and will fail to catch regressions. Update the assertion to expect a failure return (e.g., ExpectIntNE(..., 0) or compare against the project’s standard failure code for this API).

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

@JacobBarthelmeh
Copy link
Contributor

Jenkins retest this please.

I could not reproduce test failure locally.

bash-3.2$ ./tests/unit.test -924
starting unit tests...
 Begin API Tests
  Begin Group: ossl_dh
    924: test_wolfSSL_DH                                    : passed (  0.13234)
  End Group  : ossl_dh
 End API Tests
 Failed/Skipped/Passed/All: 0/0/1/1

@JacobBarthelmeh
Copy link
Contributor

Scan-Build Analysis shows that it is waiting for status to be reported, but when I click on the link and view the test it shows as completed successfully. Run #15688 (Feb 25, 2026, 3:07:30 PM)

@JacobBarthelmeh JacobBarthelmeh merged commit 76816a0 into wolfSSL:master Feb 25, 2026
453 of 462 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