]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: similar to scp, fix implicit destination path selection
authordjm@openbsd.org <djm@openbsd.org>
Mon, 13 Oct 2025 00:54:29 +0000 (00:54 +0000)
committerDamien Miller <djm@mindrot.org>
Mon, 13 Oct 2025 00:57:00 +0000 (11:57 +1100)
when source path ends with ".."; ok deraadt@

OpenBSD-Commit-ID: 9b8d2a662d96b241293a88b3ea21f2419bfc4812

sftp.c

diff --git a/sftp.c b/sftp.c
index 57516a73a683285cf426a3a8d188c6d06d3392ed..c463899c4b067c8841b7b8e7fa0b182c83ad5554 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.246 2025/10/08 21:48:40 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.247 2025/10/13 00:54:29 djm Exp $ */
 /*
  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
  *
@@ -679,6 +679,10 @@ process_get(struct sftp_conn *conn, const char *src, const char *dst,
                        goto out;
                }
 
+               /* Special handling for dest of '..' */
+               if (strcmp(filename, "..") == 0)
+                       filename = "."; /* Download to dest, not dest/.. */
+
                if (g.gl_matchc == 1 && dst) {
                        if (local_is_dir(dst)) {
                                abs_dst = sftp_path_append(dst, filename);
@@ -773,6 +777,9 @@ process_put(struct sftp_conn *conn, const char *src, const char *dst,
                        err = -1;
                        goto out;
                }
+               /* Special handling for source of '..' */
+               if (strcmp(filename, "..") == 0)
+                       filename = "."; /* Upload to dest, not dest/.. */
 
                free(abs_dst);
                abs_dst = NULL;