[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Consume only up to 8 bit octal input for backslash-escaped chars (echo,
From: |
Roman Rakus |
Subject: |
Consume only up to 8 bit octal input for backslash-escaped chars (echo, printf) |
Date: |
Tue, 07 Dec 2010 17:12:19 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101027 Fedora/3.1.6-1.fc13 Lightning/1.0b3pre Thunderbird/3.1.6 |
This one is already reported on coreutils:
http://debbugs.gnu.org/cgi/bugreport.cgi?msg=2;bug=7574
The problem is with numbers higher than /0377; echo and printf consumes
all 3 numbers, but it is not 8-bit number. For example:
$ echo -e '\0610'; printf '\610 %b\n' '\610 \0610'
Should output:
10
10 10 10
instead of
�
� � �
So, if the first octal digit is > 3, use up to 2 digits.
Patch follows for echo and printf. Is anything else counting octal values?
RR
---
diff -up bash-4.1/builtins/printf.def.octal bash-4.1/builtins/printf.def
--- bash-4.1/builtins/printf.def.octal 2010-12-07 15:40:24.000000000 +0100
+++ bash-4.1/builtins/printf.def 2010-12-07 16:13:41.000000000 +0100
@@ -734,11 +734,15 @@ tescape (estart, cp, sawc)
/* The octal escape sequences are `\0' followed by up to three octal
digits (if SAWC), or `\' followed by up to three octal digits (if
- !SAWC). As an extension, we allow the latter form even if SAWC. */
+ !SAWC). As an extension, we allow the latter form even if SAWC.
+ If the octal character begins with number 4 or higher,
+ only 2 octal digits fit to byte */
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
evalue = OCTVALUE (c);
- for (temp = 2 + (!evalue && !!sawc); ISOCTAL (*p) && temp--; p++)
+ for (temp = 2 + (!evalue && !!sawc) -
+ (!sawc ? c > '3' : evalue ? evalue > 3 : *p > '3');
+ ISOCTAL (*p) && temp--; p++)
evalue = (evalue * 8) + OCTVALUE (*p);
*cp = evalue & 0xFF;
break;
diff -up bash-4.1/lib/sh/strtrans.c.octal bash-4.1/lib/sh/strtrans.c
--- bash-4.1/lib/sh/strtrans.c.octal 2008-08-12 19:49:12.000000000 +0200
+++ bash-4.1/lib/sh/strtrans.c 2010-12-07 15:40:24.000000000 +0100
@@ -96,6 +96,8 @@ ansicstr (string, len, flags, sawc, rlen
POSIX-2001 requirement and accept 0-3 octal digits after
a leading `0'. */
temp = 2 + ((flags & 1) && (c == '0'));
+ if (*s > '3')
+ temp--;
for (c -= '0'; ISOCTAL (*s) && temp--; s++)
c = (c * 8) + OCTVALUE (*s);
c &= 0xFF;
- Consume only up to 8 bit octal input for backslash-escaped chars (echo, printf),
Roman Rakus <=