Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the non-Windows wolfSSH_SFTP_RecvOpen() error path so an SFTP STATUS failure packet can still be constructed and sent when OPEN fails (instead of returning a fatal error without responding).
Changes:
- Move
outbuffer allocation outside theif (ret == WS_SUCCESS)guard so the failure-status path can populateout. - Preserve existing success-path packet creation while enabling error-path status packet creation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
In the non-Windows (non-USE_WINDOWS_API) variant of wolfSSH_SFTP_RecvOpen, the output buffer out is only allocated inside the if (ret == WS_SUCCESS) guard at line 2175. When the file open fails (e.g., fd < 0 at line 2144 sets ret = WS_BAD_FILE_E), out remains NULL. The else branch at line 2198 then calls wolfSSH_SFTP_CreateStatus(ssh, ..., out, &outSz) with out == NULL, which returns WS_SIZE_ONLY (not WS_SUCCESS). This triggers the error handler at line 2201, returning WS_FATAL_ERROR without ever sending the proper SFTP failure status packet to the client.
Also, wolfSSH_SFTP_RecvOpen() handles multiple resources and the handling is a bit complicated.
Changes
This PR moves the out buffer allocation to outside of if (ret== WS_SUCCESS) guard to send the SFTP failure status packet in error path correctly.
Also, this adds the cleanup phase to release multiple resources in a centralized way especially for error path.
Additionally, create new sftp test case for non-existing file scenario.