Skip to content

Fix the resources management#905

Open
yosuke-wolfssl wants to merge 2 commits intowolfSSL:masterfrom
yosuke-wolfssl:f_1678
Open

Fix the resources management#905
yosuke-wolfssl wants to merge 2 commits intowolfSSL:masterfrom
yosuke-wolfssl:f_1678

Conversation

@yosuke-wolfssl
Copy link
Copy Markdown
Contributor

@yosuke-wolfssl yosuke-wolfssl commented Apr 2, 2026

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.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Apr 2, 2026
Copilot AI review requested due to automatic review settings April 2, 2026 23:41
Copy link
Copy Markdown
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

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 out buffer allocation outside the if (ret == WS_SUCCESS) guard so the failure-status path can populate out.
  • 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.

@yosuke-wolfssl yosuke-wolfssl changed the title Move the out buffer allocation Fix the resources management Apr 3, 2026
Copilot AI review requested due to automatic review settings April 3, 2026 00:45
Copy link
Copy Markdown
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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants