Skip to content

Ensure the length computed by CheckHeaders in the SSL sniffer does not exceed the actual size of the packets.#9947

Open
kareem-wolfssl wants to merge 2 commits intowolfSSL:masterfrom
kareem-wolfssl:zd21325
Open

Ensure the length computed by CheckHeaders in the SSL sniffer does not exceed the actual size of the packets.#9947
kareem-wolfssl wants to merge 2 commits intowolfSSL:masterfrom
kareem-wolfssl:zd21325

Conversation

@kareem-wolfssl
Copy link
Contributor

@kareem-wolfssl kareem-wolfssl commented Mar 10, 2026

Description

Fixes zd#21325

Thanks to Haruto Kimura (Stella) for the report.

Testing

Provided reproducer + built in tests

Checklist

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

@kareem-wolfssl kareem-wolfssl requested a review from lealem47 March 10, 2026 23:04
@kareem-wolfssl kareem-wolfssl self-assigned this Mar 10, 2026
Copilot AI review requested due to automatic review settings March 10, 2026 23:04
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

Prevents the SSL sniffer’s CheckHeaders length calculation from reporting more SSL bytes than are actually available in the captured packet, avoiding out-of-bounds parsing.

Changes:

  • Added a bounds check to ensure *sslBytes does not exceed the remaining captured packet length.
  • On mismatch, sets an error and returns WOLFSSL_FATAL_ERROR.

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

Comment on lines +5513 to +5517
/* Ensure sslBytes does not exceed the actual size. */
if (*sslBytes > (int)(length - (*sslFrame - packet))) {
SetError(PACKET_HDR_SHORT_STR, error, NULL, 0);
return WOLFSSL_FATAL_ERROR;
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The expression (length - (*sslFrame - packet)) mixes length with a pointer-difference. If length is an unsigned type (common for packet sizes), and (*sslFrame - packet) is greater than length, the subtraction can underflow and yield a large value, potentially bypassing the intended safety check. Consider splitting this into (1) an explicit check that the frame offset is within length, and (2) computing remaining = length - offset using a single, consistent unsigned type (e.g., size_t) before comparing to *sslBytes.

Copilot uses AI. Check for mistakes.

/* Ensure sslBytes does not exceed the actual size. */
if (*sslBytes > (int)(length - (*sslFrame - packet))) {
SetError(PACKET_HDR_SHORT_STR, error, NULL, 0);
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

PACKET_HDR_SHORT_STR may be misleading here since the failure is specifically “computed SSL bytes exceed captured packet length” (an internal inconsistency) rather than simply a short header. If the project has a more specific error for length inconsistencies, prefer that; otherwise consider introducing/using an error string that states the SSL record length exceeds the available captured bytes to improve diagnosability.

Suggested change
SetError(PACKET_HDR_SHORT_STR, error, NULL, 0);
SetError("SSL record length exceeds available captured bytes",
error, NULL, 0);

Copilot uses AI. Check for mistakes.
…t exceed the actual size of the packets.

Thanks to Haruto Kimura (Stella) for the report.
@philljj
Copy link
Contributor

philljj commented Mar 12, 2026

Retest this please.

@kareem-wolfssl kareem-wolfssl added the For This Release Release version 5.9.0 label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For This Release Release version 5.9.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants