Repository navigation
sftpclient: command dispatch, path, and LS fixes - #1406
ejohnstown wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
READDIR can report a partial listing as successful without receiving EOF when STATUS(OK) or NAME decoding/allocation failures leave no error recorded.
1 open issue
What changed in this PR
Improves the example SFTP client’s command handling and the library’s directory-listing error handling.
Changes:
- Matches whole command keywords and preserves directory names beginning with
... - Frees remote-path allocations on early returns.
- Tracks listing status, rejects partial results on errors, and adds regression tests.
| File | Description |
|---|---|
| wolfssh/wolfsftp.h | Documents listing results and failure behavior. |
| wolfssh/internal.h | Adds NAME-response status tracking. |
| tests/unit.c | Tests listing EOF and failure statuses. |
| tests/sftp.c | Tests command dispatch, paths, and unsupported commands. |
| src/wolfsftp.c | Distinguishes listing EOF from errors and preserves failures. |
| examples/sftpclient/sftpclient.c | Fixes dispatch, path cleanup, and allocation cleanup. |
Review effort: Balanced
aeed3b9 to
af9ec69
Compare
|
@claude review |
There was a problem hiding this comment.
Findings marked 🟡 are optional suggestions and need no follow-up push.
Additional findings (outside the current diff — GitHub can't attach inline comments there):
-
🟣
src/wolfsftp.c— pre-existing: Callers of wolfSSH_SFTP_LS see a directory they cannot open (permission denied, handle cap) as empty, which the new contract at wolfsftp.h:304 now promises. When the OPENDIR or CLOSE reply is a failure STATUS, wolfSSH_SFTP_GetHandle and wolfSSH_SFTP_Close return an error but leave ssh->error at WS_SUCCESS. LS then returns NULL with no error set. Fix: on every non-retry failure branch in LS (OPENDIR, GETHANDLE, CLOSE), set ssh->error to the step's return code when it is still WS_SUCCESS, so NULL with no error only ever means EOF on an empty listing.Why this was flagged
The trigger is LS on a path that REALPATH resolves but OPENDIR rejects. The wolfSSH server answers with STATUS: PERMISSION from GetAndCleanPath, "Too Many Open Directory Handles", or NOFILE when WOPENDIR fails (src/wolfsftp.c:3246-3273). wolfSSH_SFTP_GetHandle maps that STATUS to ret = WS_SFTP_STATUS_NOT_OK (src/wolfsftp.c:8073) and never writes ssh->error. ssh->error is still WS_SUCCESS because wolfSSH_stream_read sets it at src/ssh.c:1534. The LS GETHANDLE branch (src/wolfsftp.c:8201-8209) then clears state and returns NULL with ssh->error == WS_SUCCESS. The base returned NULL here too, but its doc said NULL means failure. This PR replaces that doc with the wolfsftp.h:304-306 rule that NULL with no error is an empty directory. The new unit tests (tests/unit.c:28414-28480) stage only READDIR failures, so they do not catch this.
Verification: pre-existing. GetHandle then sets
ret = WS_SFTP_STATUS_NOT_OK;(src/wolfsftp.c:8073) and returns it from CLEANUP (8116) without touching ssh->error. The LS GETHANDLE branch (8201-8209) sees an error that is not a retry code, clears the state and returns NULL. The new contract added in wolfssh/wolfsftp.h:304-306 says "NULL with no error is an empty directory".
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1406
Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 4 of 6 in-scope changed file(s) opened by the reviewer; not opened: wolfssh/internal.h, wolfssh/wolfsftp.h
Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max
doCmds() picks a command only when its keyword is the first word of the line, followed by a blank or the end of the line. A keyword inside a file name or inside another command no longer selects that command, so "rm getlog" removes getlog instead of fetching og. - sftpCmdArgs() returns the argument text, skipping blanks around the keyword; every command uses it, creat included - lcd and lls report "not supported" where they are compiled out - tests: rm of getlog, cdrom and tmkdir must remove the files; pwd and ls ended by a CR Issue: F-14766, F-16749
The mkdir, get, put, cd, rmdir, rm and rename branches of doCmds() free the heap-built remote path (and rename's target) before every early return, as creat and chmod already do. The leak mattered when the client runs in-process under tests/sftp.c. Issue: F-16752
clean_path() treats ".." as the parent only when it is a complete path component, followed by '/' or the end of the path. A directory such as "..dots" is kept, so cd into it no longer moves up a level. - tests: cd into ..dots and check pwd Issue: F-11666
wolfSSH_SFTP_LS() ends a listing only on SSH_FX_EOF or an empty NAME, and every step that fails leaves an error set, so NULL with no error is an empty directory. A READDIR failure still closes the handle, then frees the entries read so far. - wolfSSH_SFTP_DoName() records how a NAME request ended and sets an error on every failure, STATUS(OK) included: it carries no names - SendPacketType() sets the error when its buffer allocation fails - sftpclient ls prints an error when the listing fails - tests: each LS outcome from OPENDIR to CLOSE, and each allocation in LS failing in turn; ls of a removed working directory Issue: F-18849
af9ec69 to
402196e
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1406
Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 2 of 5 in-scope changed file(s) opened by the reviewer; not opened: tests/sftp.c, tests/unit.c, wolfssh/internal.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
Fenrir's latest completed scan found no issues; clearing the prior automated change request.

Fixes to the example SFTP client's command handling and to the library's directory listing, each with tests.
doCmds()selects a command only on the first word of the line, sorm getlogremoves getlog instead of fetchingog(F-14766, F-16749)doCmds()frees the remote path on every early return (F-16752)clean_path()drops..only as a whole path component, socd ..dotsstays put (F-11666)wolfSSH_SFTP_LS()ends a listing only onSSH_FX_EOF; any other status frees the partial list and returns NULL with the error kept (F-18849)