Skip to content

Bound READDIR and fix SFTP server status codes - #1332

Open
ejohnstown wants to merge 4 commits into
wolfSSL:masterfrom
ejohnstown:sftpdir
Open

ejohnstown wants to merge 4 commits into
wolfSSL:masterfrom
ejohnstown:sftpdir

Conversation

@ejohnstown

@ejohnstown ejohnstown commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

SFTP server fixes for directory listing and status codes. READDIR replies
are bounded and resumable, errors no longer look like EOF, and failed calls
report why on POSIX.

  • Unknown requests answer SSH_FX_OP_UNSUPPORTED.
  • READDIR sends at most WOLFSSH_MAX_SFTP_READDIR (default 100) entries per
    reply; a real error answers SSH_FX_FAILURE, and an entry whose full path
    is too long is listed without attributes.
  • OPENDIR links its handle only once the HANDLE reply is built. The Windows
    branch is compile-checked by CI only.
  • STAT, LSTAT, OPEN, REMOVE, RENAME and OPENDIR map ENOENT/ENOTDIR to
    NO_SUCH_FILE and EACCES/EPERM to PERMISSION_DENIED; other ports keep
    their old status.

Behavior to note: a SFTP_Name_readdir hook failure other than
WS_MEMORY_E ends the listing, and OPENDIR on a regular file answers
NO_SUCH_FILE, as in OpenSSH.

Fenrir: F-8840, F-10551, F-10552, F-13429, F-16081

wolfSSH_SFTP_read() answers a request type it has no handler for,
SSH_FXP_EXTENDED among them, with SSH_FX_OP_UNSUPPORTED rather than
the generic SSH_FX_FAILURE (draft-ietf-secsh-filexfer-02 Section 7).

Issue: F-8840
RecvReadDir() puts at most WOLFSSH_MAX_SFTP_READDIR entries (default
100) in one NAME reply and keeps the handle's place, so a large
directory takes several requests. The readdir helpers return WS_EOF at
the end of the directory; any other failure, an allocation included,
answers SSH_FX_FAILURE instead of EOF or a short listing.

- free the entry list on every path
- the POSIX helper tells a readdir() error from the end by errno
- an entry whose full path does not fit is listed without attributes
- a SFTP_Name_readdir hook failure other than WS_MEMORY_E ends the
  listing; WS_NEXT_ERROR still marks the last entry
- WOLFSSH_MAX_SFTP_READDIR below 1 is a build error

Issue: F-10552, F-13429
RecvOpenDir() allocates the directory node, its name and the HANDLE
reply before linking the node into dirList, so an allocation failure
leaves no handle the peer was never told about. Both the POSIX and the
Windows branch.

Issue: F-10551
STAT, LSTAT, OPEN, REMOVE, RENAME and OPENDIR take the status for a
failed call from errno, as OpenSSH's sftp-server does: ENOENT and
ENOTDIR answer SSH_FX_NO_SUCH_FILE, EACCES and EPERM
SSH_FX_PERMISSION_DENIED, anything else SSH_FX_FAILURE. Only the
default POSIX file system sets errno; other ports keep their old status.

- OPENDIR on POSIX no longer reports every failure as NO_SUCH_FILE

Issue: F-16081
Copilot AI balanced review requested due to automatic review settings October 20, 2026 21:37

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@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 #1332

Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 2 of 5 in-scope changed file(s) opened by the reviewer; not opened: tests/unit.c, wolfssh/port.h, wolfssh/wolfsftp.h

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

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