Skip to content

Commit 4b7cc26

Browse files
peffJunio C Hamano
authored andcommitted
git-am: use printf instead of echo on user-supplied strings
Under some implementations of echo (such as that provided by dash), backslash escapes are recognized without any other options. This means that echo-ing user-supplied strings may cause any backslash sequences in them to be converted. Using printf resolves the ambiguity. This bug can be seen when using git-am to apply a patch whose subject contains the character sequence "\n"; the characters are converted to a literal newline. Noticed by Szekeres Istvan. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent c1bab28 commit 4b7cc26

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

git-am.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ do
331331
ADD_SIGNOFF=
332332
fi
333333
{
334-
echo "$SUBJECT"
334+
printf '%s\n' "$SUBJECT"
335335
if test -s "$dotest/msg-clean"
336336
then
337337
echo
@@ -394,7 +394,7 @@ do
394394
fi
395395

396396
echo
397-
echo "Applying '$SUBJECT'"
397+
printf 'Applying %s\n' "$SUBJECT"
398398
echo
399399

400400
case "$resolved" in

0 commit comments

Comments
 (0)