ctdb-tests: Don't expand octal escapes in unit test output
authorMartin Schwenke <martin@meltin.net>
Mon, 26 Mar 2018 07:32:57 +0000 (18:32 +1100)
committerAmitay Isaacs <amitay@samba.org>
Tue, 27 Mar 2018 07:06:14 +0000 (09:06 +0200)
The echo command in dash expands octal escapes in strings by default
but the echo command in bash doesn't.  Since the behaviour is
ill-defined, use printf to handle affected strings.  However, ensure
that these strings aren't used as format strings.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Tue Mar 27 09:06:14 CEST 2018 on sn-devel-144

ctdb/tests/scripts/unit.sh

index 7a0296e5f3763227f6f198f646b69cdf8b5d3c72..8e72803815df8af3c73c8b89d4a74bded50211ff 100644 (file)
@@ -75,7 +75,8 @@ cat <<EOF
 Output (Exit status: ${_rc}):
 --------------------------------------------------
 EOF
-       echo "$_out" | result_filter | cat $TEST_CAT_RESULTS_OPTS
+       # Avoid echo, which might expand unintentional escapes
+       printf '%s\n' "$_out" | result_filter | cat $TEST_CAT_RESULTS_OPTS
     fi
 
     if ! $_passed ; then
@@ -84,14 +85,17 @@ EOF
 Required output (Exit status: ${required_rc}):
 --------------------------------------------------
 EOF
-       echo "$required_output" | cat $TEST_CAT_RESULTS_OPTS
+       # Avoid echo, which might expand unintentional escapes
+       printf '%s\n' "$required_output" | cat $TEST_CAT_RESULTS_OPTS
 
        if $TEST_DIFF_RESULTS ; then
            _outr=$(mktemp)
-           echo "$required_output" >"$_outr"
+           # Avoid echo, which might expand unintentional escapes
+           printf '%s\n' "$required_output" >"$_outr"
 
            _outf=$(mktemp)
-           echo "$_fout" >"$_outf"
+           # Avoid echo, which might expand unintentional escapes
+           printf '%s\n' "$_fout" >"$_outf"
 
            cat <<EOF
 --------------------------------------------------
@@ -143,7 +147,8 @@ result_check ()
 {
     _rc=$?
 
-    _fout=$(echo "$_out" | result_filter)
+    # Avoid echo, which might expand unintentional escapes
+    _fout=$(printf '%s\n' "$_out" | result_filter)
 
     if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
        _passed=true