Repository navigation
SCP sink and source edge cases - #1405
ejohnstown wants to merge 7 commits into
Conversation
ReceiveScpMessage() keeps reading until a newline when a channel read returns 0, as zero-length CHANNEL_DATA does. It returned that 0 as success, and DoScpSink() then acted on a stale or zero-initialized record type, running NEW_FILE with a NULL name on a first record. - regress: zero-length data ahead of a D record Issue: F-18863
The Nucleus branches of wsScpRecvCallback() build each path with ScpRecvNucleusPath(), which fails when a name does not fit. A dropped name still counted a directory level, so a later END_DIR climbed above the destination. - NEW_DIR commits the built path only after it succeeds, and refuses one with no room for the "/.." that END_DIR appends - END_DIR aborts when "/.." does not fit Issue: F-18862
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical flaws allow extra download records to create or truncate unintended local files and embedded newlines in outgoing names to split SCP records.
3 open issues
What changed in this PR
Hardens wolfSSH’s SCP sender and receiver against malformed records and transfer edge cases, aligning receiver behavior with OpenSSH.
Changes:
- Continues reading past empty channel data and stale channel IDs.
- Tightens recursion, filename, and Nucleus path checks; skips newline-bearing recursive entries.
- Adds tests and documents download restrictions.
| File | Description |
|---|---|
| wolfssh/wolfscp.h | Documents recursion and requested-name restrictions. |
| wolfssh/internal.h | Adds expected-name state and test helper declarations. |
| tests/unit.c | Tests grouped options and download-policy helpers. |
| tests/regress.c | Tests channel events and incoming-record validation. |
| tests/api.c | Tests newline-entry skipping and adjusts fixture names. |
| src/wolfscp.c | Implements SCP validation and transfer-handling changes. |
| src/internal.c | Frees expected-name storage during cleanup. |
Review effort: Balanced
A send skips a file or directory whose name holds a newline, with a warning for the peer, as the newline would end its C or D record early and the rest of the name would be read as more records. That covers a recursive entry and a single file. A send callback that returns such a name ends the transfer with an error record instead. - ScpSetSkipMsg() shows control bytes in the path as '?' - DoScpSource() refuses a newline name from any send callback - api: newline entry and single file skipped, warning text checked - regress: a callback's newline name sends no C record Issue: F-18864
ReceiveScpMessage() keeps reading when the worker reports an id for a channel already closed, as lastRxId can after DoChannelClose(). That status no longer reaches the return value, where an E or warning record, which sets none of its own, returned WS_INVALID_CHANID. - regress: stale receive id ahead of an E record Issue: F-18780
516069b to
14a24f3
Compare
|
@claude review |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1405
Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 5 of 7 in-scope changed file(s) opened by the reviewer; not opened: tests/regress.c, wolfssh/wolfscp.h
Findings: 1
1 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
The sink fails a D record unless the scp command carried -r, as OpenSSH scp does: the peer's for the server, the one it sent for the client. It also checks the name of a first record the local name replaces, which it took unread before. - ScpCheckFileName() shared by both name paths; a renamed D may be ".", and a renamed name may hold the '\' or ':' only a local path forbids - ParseScpCommand() reads every letter of an option group - ScpCmdIsRecursive() reads -r from the options after the scp word in the client's command, and takes one with no scp word as recursive - unit: option scans; regress: D refused and taken on both sides, bad renamed names, a renamed '\' name taken Issue: F-16809
14a24f3 to
8a42057
Compare
A non-recursive wolfSSH_SCP_from() whose src is a plain path fails a file record not named as src's last component, as OpenSSH scp checks names; a src the shell could rewrite leaves names unchecked. No record lands beside a target that is not a directory: without -r it takes every file, and a renamed recursive root is the whole transfer. - ScpSetRequestName() keeps the expected name in scpRequestName, and the local name is reset at the start of each transfer - the sink refuses a top-level record after a root that took the local name, as OpenSSH's does - ParseScpCommand() honors -d, and the sink refuses its target up front when that is not a directory - api: two send callbacks now send the name their test requests - unit: which src paths are checked; regress: names refused and taken, the local name kept for every file without -r, a -d target refused, a record after a renamed root refused Issue: F-16809
wolfSSH_CleanPath() keeps the trailing separator on a root of three characters or fewer, so "ab/" reached the send callback as is and went out as a D record with an empty name, which the sink refuses. The recursive root now drops its trailing separators before the name is taken, as OpenSSH scp does, and a root with no name aborts. - name and symlink checks share the stripped root - the name is checked before the directory is opened - a root name with a newline is skipped with a warning, as other names are - api: "sr/" sends "sr", "/" aborts, a newline root is skipped Issue: F-18778
8a42057 to
553db21
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1405
Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 1 of 5 in-scope changed file(s) opened by the reviewer; not opened: src/internal.c, tests/regress.c, wolfssh/internal.h, wolfssh/wolfscp.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.


Tightens what the SCP receiver accepts and fixes a few stalls and
truncations on both ends, matching OpenSSH scp where it has a rule.
application send callback returns one
-r; a renamed record's name must still be one path part
lands beside a target that is not a directory, and scp -d to one fails
Issue: F-18862, F-18863, F-18864, F-18780, F-16809, F-18778