summaryrefslogtreecommitdiff
path: root/sftp.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2012-10-05 10:46:16 +1000
committerDarren Tucker <dtucker@zip.com.au>2012-10-05 10:46:16 +1000
commit17146d369cd5f2c0088e4e299974ea3f87f37d4a (patch)
tree489dcca335772287abba77ccf21f701a1e5424b2 /sftp.c
parent191fcc6e4e6173a59720da043bc85618a4107fcf (diff)
- dtucker@cvs.openbsd.org 2012/09/21 10:55:04
[sftp.c] Fix handling of filenames containing escaped globbing characters and escape "#" and "*". Patch from Jean-Marc Robert via tech@, ok djm.
Diffstat (limited to 'sftp.c')
-rw-r--r--sftp.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/sftp.c b/sftp.c
index 9ab4e9f16..7b91e0013 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.139 2012/09/21 10:53:07 dtucker Exp $ */ 1/* $OpenBSD: sftp.c,v 1.140 2012/09/21 10:55:04 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -1699,7 +1699,7 @@ complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path,
1699{ 1699{
1700 glob_t g; 1700 glob_t g;
1701 char *tmp, *tmp2, ins[3]; 1701 char *tmp, *tmp2, ins[3];
1702 u_int i, hadglob, pwdlen, len, tmplen, filelen, isabs; 1702 u_int i, hadglob, pwdlen, len, tmplen, filelen, cesc, isesc, isabs;
1703 const LineInfo *lf; 1703 const LineInfo *lf;
1704 1704
1705 /* Glob from "file" location */ 1705 /* Glob from "file" location */
@@ -1754,8 +1754,18 @@ complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path,
1754 tmplen = strlen(tmp); 1754 tmplen = strlen(tmp);
1755 filelen = strlen(file); 1755 filelen = strlen(file);
1756 1756
1757 if (tmplen > filelen) { 1757 /* Count the number of escaped characters in the input string. */
1758 tmp2 = tmp + filelen; 1758 cesc = isesc = 0;
1759 for (i = 0; i < filelen; i++) {
1760 if (!isesc && file[i] == '\\' && i + 1 < filelen){
1761 isesc = 1;
1762 cesc++;
1763 } else
1764 isesc = 0;
1765 }
1766
1767 if (tmplen > (filelen - cesc)) {
1768 tmp2 = tmp + filelen - cesc;
1759 len = strlen(tmp2); 1769 len = strlen(tmp2);
1760 /* quote argument on way out */ 1770 /* quote argument on way out */
1761 for (i = 0; i < len; i++) { 1771 for (i = 0; i < len; i++) {
@@ -1769,6 +1779,8 @@ complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path,
1769 case '\t': 1779 case '\t':
1770 case '[': 1780 case '[':
1771 case ' ': 1781 case ' ':
1782 case '#':
1783 case '*':
1772 if (quote == '\0' || tmp2[i] == quote) { 1784 if (quote == '\0' || tmp2[i] == quote) {
1773 if (el_insertstr(el, ins) == -1) 1785 if (el_insertstr(el, ins) == -1)
1774 fatal("el_insertstr " 1786 fatal("el_insertstr "