Reject SFTP resume names that fill the whole name field#1105
Open
yosuke-wolfssl wants to merge 1 commit into
Open
Reject SFTP resume names that fill the whole name field#1105yosuke-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 pull request fixes an out-of-bounds write in wolfSSH_SFTP_SaveOfst() by rejecting from/to filenames whose lengths exactly equal WOLFSSH_MAX_FILENAME (leaving no space for the terminating NUL) and adds an API-level regression test to ensure the boundary behavior is correct.
Changes:
- Tighten the filename length guard in
wolfSSH_SFTP_SaveOfst()from>to>=to prevent writing the terminator one byte past the fixed-size name buffers. - Add a new
tests/api.ctest that verifiesWOLFSSH_MAX_FILENAME-length names are rejected and thatWOLFSSH_MAX_FILENAME - 1-length names round-trip successfully.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/wolfsftp.c | Fixes the off-by-one guard to prevent OOB NUL write when saving resume state names. |
| tests/api.c | Adds a boundary-condition regression test for wolfSSH_SFTP_SaveOfst / wolfSSH_SFTP_GetOfst. |
💡 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 #1105
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.
Description
wolfSSH_SFTP_SaveOfstsaves afrom/tofile-name pair and a file offset so an interrupted reget/reput can later resume. The names are copied into the fixed-size fields ofSFTP_OFST:Both fields are
char[WOLFSSH_MAX_FILENAME](256 by default) and the copied names are NUL terminated. The length guard, however, only rejected names strictly longer than the field:When
frmSz/toSz == WOLFSSH_MAX_FILENAME, the check passes,WMEMCPYfills indices0..255, andcurrent->from[frmSz] = '\0'(and thetoequivalent) writes index 256 — one byte past the array.For the
tofield, which is the last member ofSFTP_OFST, the stray NUL lands either in the next slot'soffset[0](corrupting a saved resume offset) or, for the last slot inssh->sftpOfst[], one byte past the array into the adjacentWOLFSSHmember (char* sftpDefaultPath), corrupting the low byte of a pointer that is later dereferenced and freed.The function is a public API (
WOLFSSH_API) and is also reached internally from the reget/reput paths (wolfSSH_SFTP_Get,wolfSSH_SFTP_Put), wherefrom/toare caller-supplied file names with no upstream length clamp.Addressed by f_6812.
Fix
Change the guard from
>to>=so a name that fills the whole field, leaving no room for the terminator, is rejected withWS_BUFFER_E. Names up toWOLFSSH_MAX_FILENAME - 1characters continue to work unchanged.Testing
Added
test_wolfSSH_SFTP_SaveOfsttotests/api.c:WOLFSSH_MAX_FILENAMEcharacters (forfromand forto) is rejected withWS_BUFFER_Eand stores nothing (verified viawolfSSH_SFTP_GetOfst).WOLFSSH_MAX_FILENAME - 1) is saved and round-trips back throughwolfSSH_SFTP_GetOfstwith the correct offset.0 != -1004) and passes after.Verified with
./configure --enable-all