From ce0e60ee57a2990e892b4bda98c6d223426ee9a4 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Fri, 26 Oct 2007 14:54:12 +1000 Subject: - djm@cvs.openbsd.org 2007/10/24 03:32:35 [regress/sftp-cmds.sh regress/sftp-glob.sh regress/test-exec.sh] comprehensive tests for sftp escaping its interaction with globbing; ok dtucker@ --- regress/sftp-glob.sh | 69 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 16 deletions(-) (limited to 'regress/sftp-glob.sh') diff --git a/regress/sftp-glob.sh b/regress/sftp-glob.sh index e238356a2..d5ebf9fd6 100644 --- a/regress/sftp-glob.sh +++ b/regress/sftp-glob.sh @@ -1,28 +1,65 @@ -# $OpenBSD: sftp-glob.sh,v 1.1 2004/12/10 01:31:30 fgsch Exp $ +# $OpenBSD: sftp-glob.sh,v 1.2 2007/10/24 03:32:35 djm Exp $ # Placed in the Public Domain. tid="sftp glob" +sftp_ls() { + target=$1 + errtag=$2 + expected=$3 + unexpected=$4 + verbose "$tid: $errtag" + $ECHOE "ls -l ${target}" | \ + ${SFTP} -b - -P ${SFTPSERVER} 2>/dev/null | \ + grep -v "^sftp>" > ${RESULTS} + if [ $? -ne 0 ]; then + fail "$errtag failed" + fi + if test "x$expected" != "x" && \ + ! fgrep "$expected" ${RESULTS} >/dev/null 2>&1 ; then + fail "$expected missing from $errtag results" + fi + if test "x$unexpected" != "x" && \ + fgrep "$unexpected" ${RESULTS} >/dev/null 2>&1 ; then + fail "$unexpected present in $errtag results" + fi + rm -f ${RESULTS} +} + BASE=${OBJ}/glob +RESULTS=${OBJ}/results DIR=${BASE}/dir DATA=${DIR}/file +GLOB1="${DIR}/g-wild*" +GLOB2="${DIR}/g-wildx" +QUOTE="${DIR}/g-quote\"" +SLASH="${DIR}/g-sl\\ash" +ESLASH="${DIR}/g-slash\\" +QSLASH="${DIR}/g-qs\\\"" +SPACE="${DIR}/g-q space" + rm -rf ${BASE} mkdir -p ${DIR} -touch ${DATA} - -verbose "$tid: ls file" -echo "ls -l ${DIR}/fil*" | ${SFTP} -P ${SFTPSERVER} 2>/dev/null | \ - grep ${DATA} >/dev/null 2>&1 -if [ $? -ne 0 ]; then - fail "globbed ls file failed" -fi - -verbose "$tid: ls dir" -echo "ls -l ${BASE}/d*" | ${SFTP} -P ${SFTPSERVER} 2>/dev/null | \ - grep file >/dev/null 2>&1 -if [ $? -ne 0 ]; then - fail "globbed ls dir failed" -fi +touch "${DATA}" "${GLOB1}" "${GLOB2}" "${QUOTE}" +touch "${QSLASH}" "${ESLASH}" "${SLASH}" "${SPACE}" + +# target message expected unexpected +sftp_ls "${DIR}/fil*" "file glob" "${DATA}" "" +sftp_ls "${BASE}/d*" "dir glob" "`basename ${DATA}`" "" +sftp_ls "${DIR}/g-wild\"*\"" "quoted glob" "g-wild*" "g-wildx" +sftp_ls "${DIR}/g-wild\*" "escaped glob" "g-wild*" "g-wildx" +sftp_ls "${DIR}/g-quote\\\"" "escaped quote" "g-quote\"" "" +sftp_ls "\"${DIR}/g-quote\\\"\"" "quoted quote" "g-quote\"" "" +sftp_ls "'${DIR}/g-quote\"'" "single-quoted quote" "g-quote\"" "" +sftp_ls "${DIR}/g-sl\\\\ash" "escaped slash" "g-sl\\ash" "" +sftp_ls "'${DIR}/g-sl\\\\ash'" "quoted slash" "g-sl\\ash" "" +sftp_ls "${DIR}/g-slash\\\\" "escaped slash at EOL" "g-slash\\" "" +sftp_ls "'${DIR}/g-slash\\\\'" "quoted slash at EOL" "g-slash\\" "" +sftp_ls "${DIR}/g-qs\\\\\\\"" "escaped slash+quote" "g-qs\\\"" "" +sftp_ls "'${DIR}/g-qs\\\\\"'" "quoted slash+quote" "g-qs\\\"" "" +sftp_ls "${DIR}/g-q\\ space" "escaped space" "g-q space" "" +sftp_ls "'${DIR}/g-q space'" "quoted space" "g-q space" "" rm -rf ${BASE} + -- cgit v1.2.3 From da1e4bd3bf039cc81fc2ee3f971a3ad23fa5c51c Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Fri, 26 Oct 2007 15:35:54 +1000 Subject: - djm@cvs.openbsd.org 2007/10/26 05:30:01 [regress/sftp-glob.sh regress/test-exec.sh] remove "echo -E" crap that I added in last commit and use printf(1) for cases where we strictly require echo not to reprocess escape characters. --- ChangeLog | 6 +++++- regress/sftp-glob.sh | 4 ++-- regress/test-exec.sh | 19 ++++++++----------- 3 files changed, 15 insertions(+), 14 deletions(-) (limited to 'regress/sftp-glob.sh') diff --git a/ChangeLog b/ChangeLog index c20d611b5..1cf5e350f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -73,6 +73,10 @@ [regress/sftp-cmds.sh regress/sftp-glob.sh regress/test-exec.sh] comprehensive tests for sftp escaping its interaction with globbing; ok dtucker@ + - djm@cvs.openbsd.org 2007/10/26 05:30:01 + [regress/sftp-glob.sh regress/test-exec.sh] + remove "echo -E" crap that I added in last commit and use printf(1) for + cases where we strictly require echo not to reprocess escape characters. 20070927 - (dtucker) [configure.ac atomicio.c] Fall back to including if @@ -3344,4 +3348,4 @@ OpenServer 6 and add osr5bigcrypt support so when someone migrates passwords between UnixWare and OpenServer they will still work. OK dtucker@ -$Id: ChangeLog,v 1.4776 2007/10/26 04:54:12 djm Exp $ +$Id: ChangeLog,v 1.4777 2007/10/26 05:35:54 djm Exp $ diff --git a/regress/sftp-glob.sh b/regress/sftp-glob.sh index d5ebf9fd6..62004efc5 100644 --- a/regress/sftp-glob.sh +++ b/regress/sftp-glob.sh @@ -1,4 +1,4 @@ -# $OpenBSD: sftp-glob.sh,v 1.2 2007/10/24 03:32:35 djm Exp $ +# $OpenBSD: sftp-glob.sh,v 1.3 2007/10/26 05:30:01 djm Exp $ # Placed in the Public Domain. tid="sftp glob" @@ -9,7 +9,7 @@ sftp_ls() { expected=$3 unexpected=$4 verbose "$tid: $errtag" - $ECHOE "ls -l ${target}" | \ + printf "ls -l %s" "${target}" | \ ${SFTP} -b - -P ${SFTPSERVER} 2>/dev/null | \ grep -v "^sftp>" > ${RESULTS} if [ $? -ne 0 ]; then diff --git a/regress/test-exec.sh b/regress/test-exec.sh index 650be419e..e44778065 100644 --- a/regress/test-exec.sh +++ b/regress/test-exec.sh @@ -1,4 +1,4 @@ -# $OpenBSD: test-exec.sh,v 1.28 2005/05/20 23:14:15 djm Exp $ +# $OpenBSD: test-exec.sh,v 1.30 2007/10/26 05:30:01 djm Exp $ # Placed in the Public Domain. #SUDO=sudo @@ -30,9 +30,6 @@ else USER=`id -un` fi -# XXX platforms that don't support -E may need a replacement -ECHOE="echo -E" - OBJ=$1 if [ "x$OBJ" = "x" ]; then echo '$OBJ not defined' @@ -159,31 +156,31 @@ cleanup () trace () { - $ECHOE "trace: $@" >>$TEST_SSH_LOGFILE + echo "trace: $@" >>$TEST_SSH_LOGFILE if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then - $ECHOE "$@" + echo "$@" fi } verbose () { - $ECHOE "verbose: $@" >>$TEST_SSH_LOGFILE + echo "verbose: $@" >>$TEST_SSH_LOGFILE if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then - $ECHOE "$@" + echo "$@" fi } fail () { - $ECHOE "FAIL: $@" >>$TEST_SSH_LOGFILE + echo "FAIL: $@" >>$TEST_SSH_LOGFILE RESULT=1 - $ECHOE "$@" + echo "$@" } fatal () { - $ECHOE "FATAL: $@" >>$TEST_SSH_LOGFILE + echo "FATAL: $@" >>$TEST_SSH_LOGFILE echon "FATAL: " fail "$@" cleanup -- cgit v1.2.3 From 68d293859ed2db128003d6631b63847acf0ea79f Mon Sep 17 00:00:00 2001 From: Tim Rice Date: Fri, 7 Mar 2008 19:00:33 -0800 Subject: - (tim) [regress/sftp-glob.sh] Shell portability fix. --- ChangeLog | 3 ++- regress/sftp-glob.sh | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'regress/sftp-glob.sh') diff --git a/ChangeLog b/ChangeLog index de61e1755..4bd3b4603 100644 --- a/ChangeLog +++ b/ChangeLog @@ -37,6 +37,7 @@ - deraadt@cvs.openbsd.org 2008/03/04 21:15:42 [version.h] crank version; from djm + - (tim) [regress/sftp-glob.sh] Shell portability fix. 20080302 - (dtucker) [configure.ac] FreeBSD's glob() doesn't behave the way we expect @@ -3697,4 +3698,4 @@ OpenServer 6 and add osr5bigcrypt support so when someone migrates passwords between UnixWare and OpenServer they will still work. OK dtucker@ -$Id: ChangeLog,v 1.4859 2008/03/07 07:35:47 djm Exp $ +$Id: ChangeLog,v 1.4860 2008/03/08 03:00:33 tim Exp $ diff --git a/regress/sftp-glob.sh b/regress/sftp-glob.sh index 62004efc5..60116a748 100644 --- a/regress/sftp-glob.sh +++ b/regress/sftp-glob.sh @@ -15,9 +15,12 @@ sftp_ls() { if [ $? -ne 0 ]; then fail "$errtag failed" fi - if test "x$expected" != "x" && \ - ! fgrep "$expected" ${RESULTS} >/dev/null 2>&1 ; then + if test "x$expected" != "x" ; then + if fgrep "$expected" ${RESULTS} >/dev/null 2>&1 ; then + : + else fail "$expected missing from $errtag results" + fi fi if test "x$unexpected" != "x" && \ fgrep "$unexpected" ${RESULTS} >/dev/null 2>&1 ; then -- cgit v1.2.3