DASH Shell discussions
 help / color / mirror / Atom feed
* [PATCH] echo: fix octal escaping with \1...\7
@ 2011-10-25 21:58 Mike Frysinger
  2011-10-26  7:59 ` Stephane CHAZELAS
  2011-10-31  3:41 ` Herbert Xu
  0 siblings, 2 replies; 11+ messages in thread
From: Mike Frysinger @ 2011-10-25 21:58 UTC (permalink / raw)
  To: dash; +Cc: Herbert Xu

POSIX states that octal escape sequences should take the form \0num
when using echo.  dash however additionally treats \num as an octal
sequence.  This breaks some packages (like libtool) who attempt to
use strings with these escape sequences via variables to execute sed
(since sed ends up getting passed a byte instead of a literal \1).

The code that consumes this sequence includes a comment that indicates
it doesn't actually mean to do this.  So simplify the code a bit by
ignoring these sequences that lack a leading 0 and falling through to
the existing escape parsing logic.

before:
	$ echo '\1' | hexdump -C
	00000000  01 0a                 |..|
after:
	$ echo '\1' | hexdump -C
	00000000  5c 31 0a              |\1.|
(existing \01 sequence still works the same)

This also slightly shrinks the resulting compiled code :).

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
Note: I assume this still applies to the latest git.  The last
	checkout I have is from Sep 2010 though, and kernel.org does
	not yet have the dash tree back on it.

 src/bltin/printf.c |   16 ++++------------
 1 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/src/bltin/printf.c b/src/bltin/printf.c
index b0c3774..1d373f9 100644
--- a/src/bltin/printf.c
+++ b/src/bltin/printf.c
@@ -247,18 +247,10 @@ conv_escape_str(char *str)
 		 * They start with a \0, and are followed by 0, 1, 2, 
 		 * or 3 octal digits. 
 		 */
-		if (ch == '0') {
-			unsigned char i;
-			i = 3;
-			ch = 0;
-			do {
-				unsigned k = octtobin(*str);
-				if (k > 7)
-					break;
-				str++;
-				ch <<= 3;
-				ch += k;
-			} while (--i);
+		if (ch >= '1' && ch <= '9') {
+			/* Filter \1...\9; let \0 fall to conv_escape(). */
+			ch = '\\';
+			--str;
 			continue;
 		}
 
-- 
1.7.6.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-10-31 18:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-25 21:58 [PATCH] echo: fix octal escaping with \1...\7 Mike Frysinger
2011-10-26  7:59 ` Stephane CHAZELAS
2011-10-31  3:41 ` Herbert Xu
2011-10-31  4:23   ` Mike Frysinger
2011-10-31 13:12     ` Eric Blake
2011-10-31 13:35       ` Paul Gilmartin
2011-10-31 14:03         ` Eric Blake
2011-10-31 14:56         ` Stephane CHAZELAS
2011-10-31 18:07       ` Harald van Dijk
2011-10-31 18:39       ` Mike Frysinger
2011-10-31 18:48         ` Harald van Dijk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox