diff mbox

scripts/hxtool: fix undefined behavour of echo

Message ID 1476628228-7425-1-git-send-email-mjt@msgid.tls.msk.ru
State New
Headers show

Commit Message

Michael Tokarev Oct. 16, 2016, 2:30 p.m. UTC
From: Daniel Shahaf <danielsh@apache.org>

Avoid undefined behaviour of echo(1) with backslashes in arguments
The behaviour is implementation-defined, different /bin/sh's behave
differently.

Signed-off-By: Michael Tokarev <mjt@tls.msk.ru>
---
Submitting this patch upstream, thank you very much!
Daniel, can you please add your Signed-off-By line?

 scripts/hxtool | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Comments

no-reply@patchew.org Oct. 16, 2016, 2:40 p.m. UTC | #1
Hi,

Your series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 1476628228-7425-1-git-send-email-mjt@msgid.tls.msk.ru
Subject: [Qemu-devel] [PATCH] scripts/hxtool: fix undefined behavour of echo

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git show --no-patch --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
af0a15c scripts/hxtool: fix undefined behavour of echo

=== OUTPUT BEGIN ===
Checking PATCH 1/1: scripts/hxtool: fix undefined behavour of echo...
ERROR: The correct form is "Signed-off-by"
#10: 
Signed-off-By: Michael Tokarev <mjt@tls.msk.ru>

total: 1 errors, 0 warnings, 68 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org
Daniel Shahaf Oct. 16, 2016, 3:22 p.m. UTC | #2
Michael Tokarev wrote on Sun, Oct 16, 2016 at 17:30:28 +0300:
> From: Daniel Shahaf <danielsh@apache.org>
> 
> Avoid undefined behaviour of echo(1) with backslashes in arguments
> The behaviour is implementation-defined, different /bin/sh's behave
> differently.
> 

Signed-off-by: Daniel Shahaf <danielsh@apache.org>

> Signed-off-By: Michael Tokarev <mjt@tls.msk.ru>
> ---
> Submitting this patch upstream, thank you very much!
> Daniel, can you please add your Signed-off-By line?

Like this?

Thank you for forwarding the patch upstream.

Daniel
Michael Tokarev Oct. 16, 2016, 3:26 p.m. UTC | #3
16.10.2016 18:22, Daniel Shahaf wrote:

> Signed-off-by: Daniel Shahaf <danielsh@apache.org>
> Like this?

Yes, exactly, thank you! :)

/mjt
diff mbox

Patch

diff --git a/scripts/hxtool b/scripts/hxtool
index 995bb7f..04f7d7b 100644
--- a/scripts/hxtool
+++ b/scripts/hxtool
@@ -26,32 +26,32 @@  hxtotexi()
             ;;
             STEXI*)
             if test $flag -eq 1 ; then
-                echo "line $line: syntax error: expected ETEXI, found $str" >&2
+                printf "line %d: syntax error: expected ETEXI, found '%s'\n" "$line" "$str" >&2
                 exit 1
             fi
             flag=1
             ;;
             ETEXI*)
             if test $flag -ne 1 ; then
-                echo "line $line: syntax error: expected STEXI, found $str" >&2
+                printf "line %d: syntax error: expected STEXI, found '%s'\n" "$line" "$str" >&2
                 exit 1
             fi
             flag=0
             ;;
             SQMP*|EQMP*)
             if test $flag -eq 1 ; then
-                echo "line $line: syntax error: expected ETEXI, found $str" >&2
+                printf "line %d: syntax error: expected ETEXI, found '%s'\n" "$line" "$str" >&2
                 exit 1
             fi
             ;;
             DEFHEADING*)
-            echo "$(expr "$str" : "DEFHEADING(\(.*\))")"
+            printf '%s\n' "$(expr "$str" : "DEFHEADING(\(.*\))")"
             ;;
             ARCHHEADING*)
-            echo "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
+            printf '%s\n' "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
             ;;
             *)
-            test $flag -eq 1 && echo "$str"
+            test $flag -eq 1 && printf '%s\n' "$str"
             ;;
         esac
         line=$((line+1))
@@ -69,26 +69,26 @@  hxtoqmp()
             ;;
             SQMP*)
             if test $flag -eq 1 ; then
-                echo "line $line: syntax error: expected EQMP, found $str" >&2
+                printf "line %d: syntax error: expected EQMP, found '%s'\n" "$line" "$str" >&2
                 exit 1
             fi
             flag=1
             ;;
             EQMP*)
             if test $flag -ne 1 ; then
-                echo "line $line: syntax error: expected SQMP, found $str" >&2
+                printf "line %d: syntax error: expected SQMP, found '%s'\n" "$line" "$str" >&2
                 exit 1
             fi
             flag=0
             ;;
             STEXI*|ETEXI*)
             if test $flag -eq 1 ; then
-                echo "line $line: syntax error: expected EQMP, found $str" >&2
+                printf "line %d: syntax error: expected EQMP, found '%s'\n" "$line" "$str" >&2
                 exit 1
             fi
             ;;
             *)
-            test $flag -eq 1 && echo "$str"
+            test $flag -eq 1 && printf '%s\n' "$str"
             ;;
         esac
         line=$((line+1))