Skip to content

SCP sink and source edge cases - #1405

Open
ejohnstown wants to merge 7 commits into
wolfSSL:masterfrom
ejohnstown:scp-edge-cases
Open

ejohnstown wants to merge 7 commits into
wolfSSL:masterfrom
ejohnstown:scp-edge-cases

Conversation

@ejohnstown

@ejohnstown ejohnstown commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Tightens what the SCP receiver accepts and fixes a few stalls and
truncations on both ends, matching OpenSSH scp where it has a rule.

  • Wait past zero-length channel data for a record instead of failing
  • Nucleus receive paths fail when the name does not fit
  • Never send a name that contains a newline: skip it, or abort when an
    application send callback returns one
  • Read past a closed channel id for the next record
  • Refuse directory records unless the scp command's own options carry
    -r; a renamed record's name must still be one path part
  • A single-file download takes only the file it asked for; nothing
    lands beside a target that is not a directory, and scp -d to one fails
  • Name a short recursive root that ends in a separator

Issue: F-18862, F-18863, F-18864, F-18780, F-16809, F-18778

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
Copilot AI balanced review requested due to automatic review settings December 2, 2026 22:28

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.

🟡 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

Comment thread src/wolfscp.c Resolved
Comment thread src/wolfscp.c Resolved
Comment thread src/wolfscp.c Resolved
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
@ejohnstown

Copy link
Copy Markdown
Contributor Author

@claude review

Comment thread src/wolfscp.c Resolved
Comment thread src/wolfscp.c Resolved

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

Comment thread src/wolfscp.c Resolved
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
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

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

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed their stale review December 3, 2026 00:29

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

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