Fix heap-buffer-overflow in TelnetLayer due to stale offset in getOption/getOptionData (#2144)#2148
Merged
seladb merged 4 commits intoMay 26, 2026
Conversation
In getOption(TelnetCommand) and getOptionData(TelnetCommand, size_t&), the 'offset' variable was calculated before getNextCommandField() advanced 'pos', causing a stale value to be used as maxLength in subsequent getFieldLen() calls. This allowed distanceToNextIAC() to set an endIt pointer past the end of the allocated buffer, triggering an out-of-bounds read in std::find() inside findNextIAC(). Fix: recalculate offset from the updated pos after getNextCommandField(). Also fix getOptionData(TelnetCommand, size_t&) which incorrectly used m_Data instead of pos when extracting field data for the matched command. Fixes: seladb#2144
Test TelnetCommandAfterDataParsingTests verifies that getOption(TelnetCommand) and getOptionData(TelnetCommand, size_t&) work correctly when user data (escaped IAC) precedes a command field, which previously caused a heap-buffer-overflow due to stale offset calculation.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #2148 +/- ##
==========================================
+ Coverage 82.66% 82.70% +0.04%
==========================================
Files 332 332
Lines 59736 59746 +10
Branches 12392 12332 -60
==========================================
+ Hits 49378 49412 +34
+ Misses 9480 8928 -552
- Partials 878 1406 +528
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
seladb
reviewed
May 25, 2026
alacrity-aya
added a commit
to alacrity-aya/PcapPlusPlus
that referenced
this pull request
May 26, 2026
- Reuse offset in TelnetLayer loops instead of introducing new variables - Rename regression test to TelentCommandInvalidDataTests - Use auto* for telnetLayer in test code - Add telnetCommandAfterData.pcap to PacketExamples for Wireshark inspection
- Reuse offset during Telnet command scans in TelnetLayer - Rename invalid-data regression test and keep registrations in sync - Use auto* in Telnet regression test code - Add telnetCommandAfterData.pcap fixture for easier packet inspection
70ac274 to
7eb471e
Compare
Contributor
Author
|
@seladb I don't know why ci failed. Can you take a look? |
Collaborator
@alacrity-aya It happens sometimes due to the environment the CI runs on. |
seladb
approved these changes
May 26, 2026
Owner
|
Thank you @alacrity-aya for working on this fix! 🙏 |
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.
Summary
Fixes #2144
This PR fixes a heap-buffer-overflow in
TelnetLayerthat occurs whencalling getOption(TelnetCommand) or getOptionData(TelnetCommand, size_t&)
on a Telnet packet where user data (escaped IAC
FF FF) precedes a command field.Root Cause
In both getOption(TelnetCommand) and getOptionData(TelnetCommand, size_t&),
the
offsetvariable was calculated before getNextCommandField() advancedpos, and then used unmodified when computingmaxLengthfor the subsequentgetFieldLen() call: