diff options
author | Darren Tucker <dtucker@cvs.openbsd.org> | 2013-06-04 20:42:37 +0000 |
---|---|---|
committer | Darren Tucker <dtucker@cvs.openbsd.org> | 2013-06-04 20:42:37 +0000 |
commit | 2dbf5fba89fb13a3b468cead1fc5d7341777ac42 (patch) | |
tree | c71916e9bd3bf713579787ccb3fd06e3eb7b9741 | |
parent | a10b24aa4fc9786963eebe98947c4d5be3912dff (diff) |
Make sftp's libedit interface marginally multibyte aware by building up the
quoted string by character instead of by byte. Prevents failures when linked
against a libedit built with wide character support (bz#1990). "looks ok" djm
-rw-r--r-- | usr.bin/ssh/sftp.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/usr.bin/ssh/sftp.c b/usr.bin/ssh/sftp.c index 1445affe223..2fc12f926e1 100644 --- a/usr.bin/ssh/sftp.c +++ b/usr.bin/ssh/sftp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sftp.c,v 1.145 2013/05/17 00:13:14 djm Exp $ */ +/* $OpenBSD: sftp.c,v 1.146 2013/06/04 20:42:36 dtucker Exp $ */ /* * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> * @@ -29,6 +29,7 @@ #include <histedit.h> #include <paths.h> #include <libgen.h> +#include <locale.h> #include <signal.h> #include <stdlib.h> #include <stdio.h> @@ -1681,8 +1682,9 @@ complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path, char *file, int remote, int lastarg, char quote, int terminated) { glob_t g; - char *tmp, *tmp2, ins[3]; + char *tmp, *tmp2, ins[8]; u_int i, hadglob, pwdlen, len, tmplen, filelen, cesc, isesc, isabs; + int clen; const LineInfo *lf; /* Glob from "file" location */ @@ -1751,10 +1753,13 @@ complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path, tmp2 = tmp + filelen - cesc; len = strlen(tmp2); /* quote argument on way out */ - for (i = 0; i < len; i++) { + for (i = 0; i < len; i += clen) { + if ((clen = mblen(tmp2 + i, len - i)) < 0 || + (size_t)clen > sizeof(ins) - 2) + fatal("invalid multibyte character"); ins[0] = '\\'; - ins[1] = tmp2[i]; - ins[2] = '\0'; + memcpy(ins + 1, tmp2 + i, clen); + ins[clen + 1] = '\0'; switch (tmp2[i]) { case '\'': case '"': @@ -2081,6 +2086,7 @@ main(int argc, char **argv) /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ sanitise_stdfd(); + setlocale(LC_CTYPE, ""); memset(&args, '\0', sizeof(args)); args.list = NULL; |