]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: when using the SFTP protocol for transfers, fix implicit
authordjm@openbsd.org <djm@openbsd.org>
Mon, 13 Oct 2025 00:53:51 +0000 (00:53 +0000)
committerDamien Miller <djm@mindrot.org>
Mon, 13 Oct 2025 00:57:00 +0000 (11:57 +1100)
destination path selection when source path ends with ".."; ok deraadt@
bz3871

OpenBSD-Commit-ID: d75b3b006386c5302ed4f67c4add18464ab36a0b

scp.c

diff --git a/scp.c b/scp.c
index c5f573cc1fde02875c079dc7dfd28671e095a6b4..85880a7923a4c98125943e94530c826ae2f70326 100644 (file)
--- a/scp.c
+++ b/scp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scp.c,v 1.268 2025/09/25 06:23:19 jsg Exp $ */
+/* $OpenBSD: scp.c,v 1.269 2025/10/13 00:53:51 djm Exp $ */
 /*
  * scp - secure remote copy.  This is basically patched BSD rcp which
  * uses ssh to do the data transfer (instead of using rcmd).
@@ -1340,6 +1340,10 @@ source_sftp(int argc, char *src, char *targ, struct sftp_conn *conn)
        if ((filename = basename(src)) == NULL)
                fatal("basename \"%s\": %s", src, strerror(errno));
 
+       /* Special handling for source of '..' */
+       if (strcmp(filename, "..") == 0)
+               filename = "."; /* Upload to dest, not dest/.. */
+
        /*
         * No need to glob here - the local shell already took care of
         * the expansions
@@ -1613,6 +1617,10 @@ sink_sftp(int argc, char *dst, const char *src, struct sftp_conn *conn)
                        goto out;
                }
 
+               /* Special handling for destination of '..' */
+               if (strcmp(filename, "..") == 0)
+                       filename = "."; /* Download to dest, not dest/.. */
+
                if (dst_is_dir)
                        abs_dst = sftp_path_append(dst, filename);
                else