diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-13 14:43:29 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-13 14:44:11 +0100 |
commit | 8de5b9f88ba9fe2f203abab9ca7d85129c3eb679 (patch) | |
tree | ddadeda2afcfaa0560fc697bbb5d884ee0363ec0 /shell/ash.c | |
parent | 3459024bf404af814cacfe90a0deb719e282ae62 (diff) | |
download | busybox-w32-8de5b9f88ba9fe2f203abab9ca7d85129c3eb679.tar.gz busybox-w32-8de5b9f88ba9fe2f203abab9ca7d85129c3eb679.tar.bz2 busybox-w32-8de5b9f88ba9fe2f203abab9ca7d85129c3eb679.zip |
ash : fix double-quoted "\z" handling
function old new delta
readtoken1 2602 2608 +6
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/shell/ash.c b/shell/ash.c index 4c1b5e409..5e281b5ce 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -6146,12 +6146,12 @@ rmescapes(char *str, int flag, int *slash_position) | |||
6146 | if (*p == '*' | 6146 | if (*p == '*' |
6147 | || *p == '?' | 6147 | || *p == '?' |
6148 | || *p == '[' | 6148 | || *p == '[' |
6149 | || *p == '\\' /* case '\' in \\ ) echo ok;; *) echo WRONG;; esac */ | 6149 | || *p == '\\' /* case '\' in \\ ) echo ok;; *) echo WRONG;; esac */ |
6150 | || *p == ']' /* case ']' in [a\]] ) echo ok;; *) echo WRONG;; esac */ | 6150 | || *p == ']' /* case ']' in [a\]] ) echo ok;; *) echo WRONG;; esac */ |
6151 | || *p == '-' /* case '-' in [a\-c]) echo ok;; *) echo WRONG;; esac */ | 6151 | || *p == '-' /* case '-' in [a\-c]) echo ok;; *) echo WRONG;; esac */ |
6152 | || *p == '!' /* case '!' in [\!] ) echo ok;; *) echo WRONG;; esac */ | 6152 | || *p == '!' /* case '!' in [\!] ) echo ok;; *) echo WRONG;; esac */ |
6153 | /* Some libc support [^negate], that's why "^" also needs love */ | 6153 | /* Some libc support [^negate], that's why "^" also needs love */ |
6154 | || *p == '^' /* case '^' in [\^] ) echo ok;; *) echo WRONG;; esac */ | 6154 | || *p == '^' /* case '^' in [\^] ) echo ok;; *) echo WRONG;; esac */ |
6155 | ) { | 6155 | ) { |
6156 | *q++ = '\\'; | 6156 | *q++ = '\\'; |
6157 | } | 6157 | } |
@@ -11992,13 +11992,24 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) | |||
11992 | USTPUTC(CTLESC, out); | 11992 | USTPUTC(CTLESC, out); |
11993 | USTPUTC('\\', out); | 11993 | USTPUTC('\\', out); |
11994 | } | 11994 | } |
11995 | /* Backslash is retained if we are in "str" and next char isn't special */ | 11995 | /* Backslash is retained if we are in "str" |
11996 | * and next char isn't dquote-special. | ||
11997 | */ | ||
11996 | if (dblquote | 11998 | if (dblquote |
11997 | && c != '\\' | 11999 | && c != '\\' |
11998 | && c != '`' | 12000 | && c != '`' |
11999 | && c != '$' | 12001 | && c != '$' |
12000 | && (c != '"' || eofmark != NULL) | 12002 | && (c != '"' || eofmark != NULL) |
12001 | ) { | 12003 | ) { |
12004 | //dash survives not doing USTPUTC(CTLESC), but merely by chance: | ||
12005 | //Example: "\z" gets encoded as "\<CTLESC>z". | ||
12006 | //rmescapes() then emits "\", "\z", protecting z from globbing. | ||
12007 | //But it's wrong, should protect _both_ from globbing: | ||
12008 | //everything in double quotes is not globbed. | ||
12009 | //Unlike dash, we have a fix in rmescapes() which emits bare "z" | ||
12010 | //for "<CTLESC>z" since "z" is not glob-special (else unicode may break), | ||
12011 | //and glob would see "\z" and eat "\". Thus: | ||
12012 | USTPUTC(CTLESC, out); /* protect '\' from glob */ | ||
12002 | USTPUTC('\\', out); | 12013 | USTPUTC('\\', out); |
12003 | } | 12014 | } |
12004 | USTPUTC(CTLESC, out); | 12015 | USTPUTC(CTLESC, out); |