examples/client: guard rxBuf indexing against negative stream_read error#1004
Open
yosuke-wolfssl wants to merge 1 commit into
Open
examples/client: guard rxBuf indexing against negative stream_read error#1004yosuke-wolfssl wants to merge 1 commit into
yosuke-wolfssl wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a potential stack out-of-bounds write (and subsequent unterminated string print) in the examples/client client_test() non-keepOpen read loop when wolfSSH_stream_read() returns an error and ret is overwritten with a negative wolfSSH_get_error() code.
Changes:
- Guard
rxBuf[ret] = '\0'so it only executes whenretis a valid positive byte count within the buffer bounds. - Guard the
"Server said: %s"print to avoid reading unterminated/uninitialized data whenretis not a byte count.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1004
Scan targets checked: wolfssh-bugs, wolfssh-src
No new issues found in the changed files. ✅
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.
Background
In client_test examples/client/client.c, the non-keepOpen read loop reuses ret for both the byte count and the error code. When wolfSSH_stream_read returns ≤0, ret is overwritten with wolfSSH_get_error(ssh). The do/while continuation only re-tests for WS_WANT_READ/WS_WANT_WRITE, so a WS_CHAN_RXD (-1057) result exits the loop with ret still negative.
The following line then did:
This is a stack out-of-bounds write and an uninitialized/un-terminated read.
Changes
Guard the terminator and print so they only run for a valid byte count:
Addressed by f_4104