Skip to content

Fix SFTP client states dropping unsent bytes after partial channel send#1008

Open
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_5574
Open

Fix SFTP client states dropping unsent bytes after partial channel send#1008
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_5574

Conversation

@yosuke-wolfssl

@yosuke-wolfssl yosuke-wolfssl commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Description

Several SFTP client request states (read, write, open, mkdir, setstat, rename) advanced their state machine as soon as wolfSSH_SFTP_buffer_send() returned, without confirming the request bytes had actually left the client. Two cases were mishandled:

  1. Clamped partial send — SendChannelData sends fewer bytes than requested (idx < sz); the old code freed/advanced past the buffer, corrupting the request stream.
  2. Socket back-pressure — the buffer reports fully consumed (idx == sz) but bytes remain queued in the SSH output buffer (wolfSSH_OutputPending), returning WS_WANT_WRITE.

Additionally, wolfSSH_SFTP_Rename used a ret <= 0 guard that treated a WS_SUCCESS (0) flush-only resume as terminal, swallowing a subsequent server rejection and returning success.

Addressed by f_5574.

Changes

  • Added a shared helper wolfSSH_SFTP_buffer_send_finish() that returns WS_WANT_WRITE unless both the buffer is fully consumed and nothing remains in the SSH output buffer. Wired it into all six affected states so each preserves its state/buffer and resumes correctly.
  • Changed the rename send guard from ret <= 0 to ret < 0 so a flush-only resume falls through to read the server's response instead of returning premature success.
  • New tests to exercise new code path with new test hooks.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Jun 9, 2026
Copilot AI review requested due to automatic review settings June 9, 2026 00:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 5 out of 5 changed files in this pull request and generated no new comments.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #1008

Scan targets checked: none
Failed targets: wolfssh-bugs, wolfssh-src

⚠️ Review incomplete — one or more scan targets failed before findings could be produced. See the Fenrir PR review detail page for logs.

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.

4 participants