From 2863c94c026ba4fb4340b2d70359ff0703bb41b9 Mon Sep 17 00:00:00 2001 From: djm Date: Mon, 27 Mar 2023 03:25:08 +0000 Subject: [PATCH] scp: when copying local->remote, check that source file exists before opening SFTP connection to the server. Based on GHPR#370 ok dtucker, markus --- usr.bin/ssh/scp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/usr.bin/ssh/scp.c b/usr.bin/ssh/scp.c index f0f09bba623..ea3deedc98e 100644 --- a/usr.bin/ssh/scp.c +++ b/usr.bin/ssh/scp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scp.c,v 1.253 2023/03/03 03:12:24 dtucker Exp $ */ +/* $OpenBSD: scp.c,v 1.254 2023/03/27 03:25:08 djm Exp $ */ /* * scp - secure remote copy. This is basically patched BSD rcp which * uses ssh to do the data transfer (instead of using rcmd). @@ -975,6 +975,7 @@ toremote(int argc, char **argv, enum scp_mode_e mode, char *sftp_direct) struct sftp_conn *conn = NULL, *conn2 = NULL; arglist alist; int i, r, status; + struct stat sb; u_int j; memset(&alist, '\0', sizeof(alist)); @@ -1117,6 +1118,11 @@ toremote(int argc, char **argv, enum scp_mode_e mode, char *sftp_direct) errs = 1; } else { /* local to remote */ if (mode == MODE_SFTP) { + /* no need to glob: already done by shell */ + if (stat(argv[i], &sb) != 0) { + fatal("stat local \"%s\": %s", argv[i], + strerror(errno)); + } if (remin == -1) { /* Connect to remote now */ conn = do_sftp_connect(thost, tuser, -- 2.20.1