Skip to content

sftp: handle an empty request path - #1403

Open
ejohnstown wants to merge 2 commits into
wolfSSL:masterfrom
ejohnstown:sftp-empty-path
Open

ejohnstown wants to merge 2 commits into
wolfSSL:masterfrom
ejohnstown:sftp-empty-path

Conversation

@ejohnstown

Copy link
Copy Markdown
Contributor

An empty SFTP path arrives as a NULL pointer, and REALPATH and every request
through GetAndCleanPath() passed it to memcpy(), which is undefined even for a
length of 0. RMDIR of an empty path also removed the start directory.

  • Copy the path only when it has bytes; an empty path still resolves to the
    start path
  • RMDIR refuses an empty path, or one starting with NUL, with NO_SUCH_FILE, as
    OpenSSH does

Issue: #1400

GetStringRef() returns a NULL pointer for a zero-length string, and
wolfSSH_SFTP_RecvRealPath() and GetAndCleanPath() passed it straight to
memcpy(). That is undefined even for a length of 0. Copy only when the
path has bytes; an empty path still resolves to the start path.

- regress: REALPATH, STAT and LSTAT with an empty path, which UBSan
  flags at both copies without the guard

Issue: wolfSSL#1400
An empty path resolves to the session's start directory, so RMDIR ""
removed it when it was empty and answered OK. Refuse an empty path, or
one that starts with NUL, with NO_SUCH_FILE and remove nothing, as
OpenSSH's sftp-server does.

- regress: REALPATH of an empty path names the start path

Issue: wolfSSL#1400

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

Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer

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: Max

@ejohnstown

Copy link
Copy Markdown
Contributor Author

@claude review

@claude claude 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.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

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