[openssh-commits] [openssh] 05/14: upstream: when doing a `sftp -r host:`, verify the host returns a
git+noreply at mindrot.org
git+noreply at mindrot.org
Thu Nov 26 10:20:50 AEDT 2026
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
commit dd239d7ba7dbb84268ddc8952d3ac891f7bab982
Author: djm at openbsd.org <djm at openbsd.org>
AuthorDate: Wed Nov 25 20:48:31 2026 +0000
upstream: when doing a `sftp -r host:`, verify the host returns a
directory and not a filename. Avoids another local file clobber.
Anthropic ANT-2026-KVP4Z2O3
OpenBSD-Commit-ID: d33b58bf3c73fe64d2ff699b2ec2d1087d49e76e
---
sftp.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/sftp.c b/sftp.c
index c9e8fb746..82fbf7e40 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.265 2026/11/25 07:11:03 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.266 2026/11/25 20:48:31 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm at openbsd.org>
*
@@ -2297,6 +2297,22 @@ complete(EditLine *el, int ch)
}
#endif /* USE_LIBEDIT */
+/*
+ * Returns nonzero if path can only refer to a directory, i.e. its final
+ * component is empty (trailing slash), "." or "..".
+ */
+static int
+path_must_be_dir(const char *path)
+{
+ const char *cp;
+
+ if ((cp = strrchr(path, '/')) == NULL)
+ cp = path;
+ else
+ cp++;
+ return *cp == '\0' || strcmp(cp, ".") == 0 || strcmp(cp, "..") == 0;
+}
+
static int
interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
{
@@ -2355,7 +2371,13 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
dir = xstrdup(file1);
dir = sftp_make_absolute(dir, remote_path);
- if (sftp_remote_is_dir(conn, dir) && file2 == NULL) {
+ /*
+ * A path that cannot name a file (trailing slash, "." or
+ * "..") is always treated as a directory regardless of what
+ * the server says; "cd" will fail if it doesn't exist.
+ */
+ if (file2 == NULL && (path_must_be_dir(file1) ||
+ sftp_remote_is_dir(conn, dir))) {
if (!quiet)
mprintf("Changing to: %s\n", dir);
r = snprintf(cmd, sizeof cmd, "cd \"%s\"", dir);
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list