diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-26 15:56:53 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-26 15:56:53 +0200 |
commit | f15aa57a7f5edcbf3098873b8798c0ea7f496ed7 (patch) | |
tree | 5641162328f080297bd9a27cf50730dbb3a8f604 /shell/ash.c | |
parent | e19923f6652a638ac39c84012e97f52cf5a7568e (diff) | |
download | busybox-w32-f15aa57a7f5edcbf3098873b8798c0ea7f496ed7.tar.gz busybox-w32-f15aa57a7f5edcbf3098873b8798c0ea7f496ed7.tar.bz2 busybox-w32-f15aa57a7f5edcbf3098873b8798c0ea7f496ed7.zip |
ash: [PARSER] Fix parsing of ${##1}
Upstream commit:
Date: Thu, 4 Oct 2007 22:15:10 +0800
[PARSER] Fix parsing of ${##1}
Previously dash treated ${##1} as a length operation. This patch fixes that.
Test case:
set -- a
echo ${##1}OK
Old result:
1OK
New result:
OK
This was a real bug in ash (but not in hush).
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/shell/ash.c b/shell/ash.c index b404449d0..2cebfe2c0 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -11728,16 +11728,9 @@ parsesub: { | |||
11728 | subtype = VSNORMAL; | 11728 | subtype = VSNORMAL; |
11729 | if (c == '{') { | 11729 | if (c == '{') { |
11730 | c = pgetc_eatbnl(); | 11730 | c = pgetc_eatbnl(); |
11731 | if (c == '#') { | 11731 | subtype = 0; |
11732 | c = pgetc_eatbnl(); | ||
11733 | if (c == '}') | ||
11734 | c = '#'; /* ${#} - same as $# */ | ||
11735 | else | ||
11736 | subtype = VSLENGTH; /* ${#VAR} */ | ||
11737 | } else { | ||
11738 | subtype = 0; | ||
11739 | } | ||
11740 | } | 11732 | } |
11733 | varname: | ||
11741 | if (c <= 255 /* not PEOA or PEOF */ && is_name(c)) { | 11734 | if (c <= 255 /* not PEOA or PEOF */ && is_name(c)) { |
11742 | /* $[{[#]]NAME[}] */ | 11735 | /* $[{[#]]NAME[}] */ |
11743 | do { | 11736 | do { |
@@ -11752,8 +11745,23 @@ parsesub: { | |||
11752 | } while (isdigit(c)); | 11745 | } while (isdigit(c)); |
11753 | } else if (is_special(c)) { | 11746 | } else if (is_special(c)) { |
11754 | /* $[{[#]]<specialchar>[}] */ | 11747 | /* $[{[#]]<specialchar>[}] */ |
11755 | USTPUTC(c, out); | 11748 | int cc = c; |
11749 | |||
11756 | c = pgetc_eatbnl(); | 11750 | c = pgetc_eatbnl(); |
11751 | if (!subtype && cc == '#') { | ||
11752 | subtype = VSLENGTH; | ||
11753 | if (c == '_' || isalnum(c)) | ||
11754 | goto varname; | ||
11755 | cc = c; | ||
11756 | c = pgetc_eatbnl(); | ||
11757 | if (cc == '}' || c != '}') { | ||
11758 | pungetc(); | ||
11759 | subtype = 0; | ||
11760 | c = cc; | ||
11761 | cc = '#'; | ||
11762 | } | ||
11763 | } | ||
11764 | USTPUTC(cc, out); | ||
11757 | } else { | 11765 | } else { |
11758 | goto badsub; | 11766 | goto badsub; |
11759 | } | 11767 | } |