diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-05-25 23:48:46 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-05-25 23:48:46 +0000 |
commit | df1b04e5ebbd86edbf64973c34d70cbf07f3f6b2 (patch) | |
tree | d95e8e32fda94d3061d4e8ad1b995c1fe1dcd7fe /usr.bin/ssh/sftp.c | |
parent | e69bd3c404b0713d8e6c45cbda62ce1e4dfd572e (diff) |
To prevent screwing up terminal settings when printing to the
terminal, for ASCII and UTF-8, escape bytes not forming characters
and bytes forming non-printable characters with vis(3) VIS_OCTAL.
For other character sets, abort printing of the current string in
these cases. In particular,
* let scp(1) respect the local user's LC_CTYPE locale(1);
* sanitize data received from the remote host;
* sanitize filenames, usernames, and similar data even locally;
* take character display widths into account for the progressmeter.
This is believed to be sufficient to keep the local terminal safe
on OpenBSD, but bad things can still happen on other systems with
state-dependent locales because many places in the code print
unencoded ASCII characters into the output stream.
Using feedback from djm@ and martijn@,
various aspects discussed with many others.
deraadt@ says it should go in now, i probably already hesitated too long
Diffstat (limited to 'usr.bin/ssh/sftp.c')
-rw-r--r-- | usr.bin/ssh/sftp.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/usr.bin/ssh/sftp.c b/usr.bin/ssh/sftp.c index 706e5486312..daeb6784d10 100644 --- a/usr.bin/ssh/sftp.c +++ b/usr.bin/ssh/sftp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sftp.c,v 1.173 2016/04/08 08:19:17 djm Exp $ */ +/* $OpenBSD: sftp.c,v 1.174 2016/05/25 23:48:45 schwarze Exp $ */ /* * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> * @@ -31,6 +31,7 @@ #include <libgen.h> #include <locale.h> #include <signal.h> +#include <stdarg.h> #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -43,6 +44,7 @@ #include "log.h" #include "pathnames.h" #include "misc.h" +#include "utf8.h" #include "sftp.h" #include "ssherr.h" @@ -622,9 +624,11 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, resume |= global_aflag; if (!quiet && resume) - printf("Resuming %s to %s\n", g.gl_pathv[i], abs_dst); + mprintf("Resuming %s to %s\n", + g.gl_pathv[i], abs_dst); else if (!quiet && !resume) - printf("Fetching %s to %s\n", g.gl_pathv[i], abs_dst); + mprintf("Fetching %s to %s\n", + g.gl_pathv[i], abs_dst); if (pathname_is_dir(g.gl_pathv[i]) && (rflag || global_rflag)) { if (download_dir(conn, g.gl_pathv[i], abs_dst, NULL, pflag || global_pflag, 1, resume, @@ -713,10 +717,11 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, resume |= global_aflag; if (!quiet && resume) - printf("Resuming upload of %s to %s\n", g.gl_pathv[i], - abs_dst); + mprintf("Resuming upload of %s to %s\n", + g.gl_pathv[i], abs_dst); else if (!quiet && !resume) - printf("Uploading %s to %s\n", g.gl_pathv[i], abs_dst); + mprintf("Uploading %s to %s\n", + g.gl_pathv[i], abs_dst); if (pathname_is_dir(g.gl_pathv[i]) && (rflag || global_rflag)) { if (upload_dir(conn, g.gl_pathv[i], abs_dst, pflag || global_pflag, 1, resume, @@ -817,12 +822,12 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag) attrib_to_stat(&d[n]->a, &sb); lname = ls_file(fname, &sb, 1, (lflag & LS_SI_UNITS)); - printf("%s\n", lname); + mprintf("%s\n", lname); free(lname); } else - printf("%s\n", d[n]->longname); + mprintf("%s\n", d[n]->longname); } else { - printf("%-*s", colspace, fname); + mprintf("%-*s", colspace, fname); if (c >= columns) { printf("\n"); c = 1; @@ -903,10 +908,10 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, } lname = ls_file(fname, g.gl_statv[i], 1, (lflag & LS_SI_UNITS)); - printf("%s\n", lname); + mprintf("%s\n", lname); free(lname); } else { - printf("%-*s", colspace, fname); + mprintf("%-*s", colspace, fname); if (c >= columns) { printf("\n"); c = 1; @@ -1434,7 +1439,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g); for (i = 0; g.gl_pathv[i] && !interrupted; i++) { if (!quiet) - printf("Removing %s\n", g.gl_pathv[i]); + mprintf("Removing %s\n", g.gl_pathv[i]); err = do_rm(conn, g.gl_pathv[i]); if (err != 0 && err_abort) break; @@ -1534,7 +1539,8 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g); for (i = 0; g.gl_pathv[i] && !interrupted; i++) { if (!quiet) - printf("Changing mode on %s\n", g.gl_pathv[i]); + mprintf("Changing mode on %s\n", + g.gl_pathv[i]); err = do_setstat(conn, g.gl_pathv[i], &a); if (err != 0 && err_abort) break; @@ -1564,12 +1570,12 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, aa->flags &= SSH2_FILEXFER_ATTR_UIDGID; if (cmdnum == I_CHOWN) { if (!quiet) - printf("Changing owner on %s\n", + mprintf("Changing owner on %s\n", g.gl_pathv[i]); aa->uid = n_arg; } else { if (!quiet) - printf("Changing group on %s\n", + mprintf("Changing group on %s\n", g.gl_pathv[i]); aa->gid = n_arg; } @@ -1579,7 +1585,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, } break; case I_PWD: - printf("Remote working directory: %s\n", *pwd); + mprintf("Remote working directory: %s\n", *pwd); break; case I_LPWD: if (!getcwd(path_buf, sizeof(path_buf))) { @@ -1587,7 +1593,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, err = -1; break; } - printf("Local working directory: %s\n", path_buf); + mprintf("Local working directory: %s\n", path_buf); break; case I_QUIT: /* Processed below */ @@ -1655,7 +1661,7 @@ complete_display(char **list, u_int len) for (y = 0; list[y]; y++) { llen = strlen(list[y]); tmp = llen > len ? list[y] + len : ""; - printf("%-*s", colspace, tmp); + mprintf("%-*s", colspace, tmp); if (m >= columns) { printf("\n"); m = 1; @@ -2036,7 +2042,7 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) if (remote_is_dir(conn, dir) && file2 == NULL) { if (!quiet) - printf("Changing to: %s\n", dir); + mprintf("Changing to: %s\n", dir); snprintf(cmd, sizeof cmd, "cd \"%s\"", dir); if (parse_dispatch_command(conn, cmd, &remote_path, 1) != 0) { @@ -2082,7 +2088,7 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) break; } if (!interactive) { /* Echo command */ - printf("sftp> %s", cmd); + mprintf("sftp> %s", cmd); if (strlen(cmd) > 0 && cmd[strlen(cmd) - 1] != '\n') printf("\n"); |