Bugzilla – Attachment 1295 Details for
Bug 778
sftp client globs entire path, directories enclosed in square brackets are unusable
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Diff with support for unquoted, escaped whitespace
sftp-space-escape.diff (text/plain), 6.34 KB, created by
Damien Miller
on 2007-05-20 22:18:10 AEST
(
hide
)
Description:
Diff with support for unquoted, escaped whitespace
Filename:
MIME Type:
Creator:
Damien Miller
Created:
2007-05-20 22:18:10 AEST
Size:
6.34 KB
patch
obsolete
>Hi, > >This merges Ben's and my diffs to support both: > >get file\ with\ spaces >get "file with \[glob metacharacters]" > >Includes regress bits based on Ben's work. > >Ok? > >-d > >Index: usr.bin/ssh/sftp.c >=================================================================== >RCS file: /cvs/src/usr.bin/ssh/sftp.c,v >retrieving revision 1.96 >diff -u -p -r1.96 sftp.c >--- usr.bin/ssh/sftp.c 3 Jan 2007 04:09:15 -0000 1.96 >+++ usr.bin/ssh/sftp.c 20 May 2007 12:05:51 -0000 >@@ -22,6 +22,7 @@ > #include <sys/socket.h> > #include <sys/param.h> > >+#include <ctype.h> > #include <errno.h> > #include <glob.h> > #include <histedit.h> >@@ -411,8 +412,8 @@ parse_ls_flags(const char **cpp, int *lf > static int > get_pathname(const char **cpp, char **path) > { >- const char *cp = *cpp, *end; >- char quot; >+ const char *cp = *cpp; >+ int quot = -1; > u_int i, j; > > cp += strspn(cp, WHITESPACE); >@@ -422,50 +423,44 @@ get_pathname(const char **cpp, char **pa > return (0); > } > >+ /* There is no possibility of expansion, so this will fit */ > *path = xmalloc(strlen(cp) + 1); > >- /* Check for quoted filenames */ >- if (*cp == '\"' || *cp == '\'') { >+ if (*cp == '\"' || *cp == '\'') > quot = *cp++; > >- /* Search for terminating quote, unescape some chars */ >- for (i = j = 0; i <= strlen(cp); i++) { >- if (cp[i] == quot) { /* Found quote */ >- i++; >- (*path)[j] = '\0'; >- break; >- } >- if (cp[i] == '\0') { /* End of string */ >- error("Unterminated quote"); >- goto fail; >- } >- if (cp[i] == '\\') { /* Escaped characters */ >- i++; >- if (cp[i] != '\'' && cp[i] != '\"' && >- cp[i] != '\\') { >- error("Bad escaped character '\\%c'", >- cp[i]); >- goto fail; >- } >- } >- (*path)[j++] = cp[i]; >+ /* >+ * Search for terminating quote or unescaped whitespace, >+ * unescaping some special characters along the way. >+ */ >+ for (i = j = 0; i <= strlen(cp); i++) { >+ if ((quot == -1 && (isspace(cp[i]) || cp[i] == '\0')) || >+ cp[i] == quot) { >+ i++; >+ (*path)[j] = '\0'; >+ break; > } >- >- if (j == 0) { >- error("Empty quotes"); >+ if (quot != -1 && cp[i] == '\0') { >+ error("Unterminated quote"); > goto fail; > } >- *cpp = cp + i + strspn(cp + i, WHITESPACE); >- } else { >- /* Read to end of filename */ >- end = strpbrk(cp, WHITESPACE); >- if (end == NULL) >- end = strchr(cp, '\0'); >- *cpp = end + strspn(end, WHITESPACE); >+ if (cp[i] == '\\') { >+ i++; >+ /* Pass unknown escape sequences through verbatim */ >+ if (cp[i] != '\'' && cp[i] != '\"' && >+ cp[i] != '\\' && >+ !(quot == -1 && isspace(cp[i]))) >+ (*path)[j++] = '\\'; >+ } >+ (*path)[j++] = cp[i]; >+ } > >- memcpy(*path, cp, end - cp); >- (*path)[end - cp] = '\0'; >+ if (j == 0) { >+ error("Empty pathname"); >+ goto fail; > } >+ >+ *cpp = cp + i + strspn(cp + i, WHITESPACE); > return (0); > > fail: >Index: regress/usr.bin/ssh/sftp-cmds.sh >=================================================================== >RCS file: /cvs/src/regress/usr.bin/ssh/sftp-cmds.sh,v >retrieving revision 1.7 >diff -u -p -r1.7 sftp-cmds.sh >--- regress/usr.bin/ssh/sftp-cmds.sh 29 Aug 2006 09:44:00 -0000 1.7 >+++ regress/usr.bin/ssh/sftp-cmds.sh 20 May 2007 12:05:51 -0000 >@@ -14,6 +14,12 @@ GLOBFILES=`(cd /bin;echo l*)` > # Path with embedded quote > QUOTECOPY=${COPY}".\"blah\"" > QUOTECOPY_ARG=${COPY}'.\"blah\"' >+# File with spaces >+SPACECOPY="${COPY} this has spaces.txt" >+SPACECOPY_ARG="${COPY}\ this\ has\ spaces.txt" >+# File with glob metacharacters >+GLOBMETACOPY="${COPY} [metachar].txt" >+GLOBMETACOPY_ARG="\"${COPY} \\[metachar].txt\"" > > rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 ${BATCH}.* > mkdir ${COPY}.dd >@@ -69,10 +75,25 @@ rm -f ${QUOTECOPY} > cp $DATA ${QUOTECOPY} > verbose "$tid: get filename with quotes" > echo "get \"$QUOTECOPY_ARG\" ${COPY}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ >- || fail "put failed" >+ || fail "get failed" > cmp ${COPY} ${QUOTECOPY} || fail "corrupted copy after get with quotes" > rm -f ${QUOTECOPY} ${COPY} > >+rm -f "$SPACECOPY" ${COPY} >+cp $DATA "$SPACECOPY" >+verbose "$tid: get filename with spaces" >+echo "get ${SPACECOPY_ARG} ${COPY}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ >+ || fail "get failed" >+cmp ${COPY} "$SPACECOPY" || fail "corrupted copy after get with spaces" >+ >+rm -f "$GLOBMETACOPY" ${COPY} >+cp $DATA "$GLOBMETACOPY" >+verbose "$tid: get filename with glob metacharacters" >+echo "get ${GLOBMETACOPY_ARG} ${COPY}" | \ >+ ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "get failed" >+cmp ${COPY} "$GLOBMETACOPY" || \ >+ fail "corrupted copy after put with glob metacharacters" >+ > rm -f ${COPY}.dd/* > verbose "$tid: get to directory" > echo "get $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ >@@ -103,16 +124,22 @@ done > > rm -f ${COPY} > verbose "$tid: put" >-echo "put $DATA $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ >- || fail "put failed" >+echo "put $DATA $COPY" | \ >+ ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed" > cmp $DATA ${COPY} || fail "corrupted copy after put" > > rm -f ${QUOTECOPY} > verbose "$tid: put filename with quotes" >-echo "put $DATA \"$QUOTECOPY_ARG\"" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ >- || fail "put failed" >+echo "put $DATA \"$QUOTECOPY_ARG\"" | \ >+ ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed" > cmp $DATA ${QUOTECOPY} || fail "corrupted copy after put with quotes" > >+rm -f "$SPACECOPY" >+verbose "$tid: put filename with spaces" >+echo "put $DATA ${SPACECOPY_ARG}" | \ >+ ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed" >+cmp $DATA "$SPACECOPY" || fail "corrupted copy after put with spaces" >+ > rm -f ${COPY}.dd/* > verbose "$tid: put to directory" > echo "put $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ >@@ -148,8 +175,9 @@ test -f ${COPY}.1 || fail "missing file > cmp $DATA ${COPY}.1 >/dev/null 2>&1 || fail "corrupted copy after rename" > > verbose "$tid: rename directory" >-echo "rename ${COPY}.dd ${COPY}.dd2" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ >- || fail "rename directory failed" >+echo "rename ${COPY}.dd ${COPY}.dd2" | \ >+ ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || \ >+ fail "rename directory failed" > test -d ${COPY}.dd && fail "oldname exists after rename directory" > test -d ${COPY}.dd2 || fail "missing newname after rename directory" > >@@ -183,6 +211,6 @@ echo "lchdir ${COPY}.dd" | ${SFTP} -P ${ > || fail "lchdir failed" > > rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 ${BATCH}.* >-rm -rf ${QUOTECOPY} >+rm -rf ${QUOTECOPY} "$SPACECOPY" "$GLOBMETACOPY" > >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 778
:
1284
|
1291
|
1295
|
1357
|
1358