diff options
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c index 03fbbee53..5c431c9ff 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -6854,8 +6854,15 @@ subevalvar(char *p, char *varname, int strloc, int subtype, | |||
6854 | if (subtype == VSREPLACE || subtype == VSREPLACEALL) { | 6854 | if (subtype == VSREPLACE || subtype == VSREPLACEALL) { |
6855 | /* Find '/' and replace with NUL */ | 6855 | /* Find '/' and replace with NUL */ |
6856 | repl = p; | 6856 | repl = p; |
6857 | /* The pattern can't be empty. | ||
6858 | * IOW: if the first char after "${v//" is a slash, | ||
6859 | * it does not terminate the pattern - it's the first char of the pattern: | ||
6860 | * v=/dev/ram; echo ${v////-} prints -dev-ram (pattern is "/") | ||
6861 | * v=/dev/ram; echo ${v///r/-} prints /dev-am (pattern is "/r") | ||
6862 | */ | ||
6863 | if (*repl == '/') | ||
6864 | repl++; | ||
6857 | for (;;) { | 6865 | for (;;) { |
6858 | /* Handle escaped slashes, e.g. "${v/\//_}" (they are CTLESC'ed by this point) */ | ||
6859 | if (*repl == '\0') { | 6866 | if (*repl == '\0') { |
6860 | repl = NULL; | 6867 | repl = NULL; |
6861 | break; | 6868 | break; |
@@ -6864,6 +6871,7 @@ subevalvar(char *p, char *varname, int strloc, int subtype, | |||
6864 | *repl = '\0'; | 6871 | *repl = '\0'; |
6865 | break; | 6872 | break; |
6866 | } | 6873 | } |
6874 | /* Handle escaped slashes, e.g. "${v/\//_}" (they are CTLESC'ed by this point) */ | ||
6867 | if ((unsigned char)*repl == CTLESC && repl[1]) | 6875 | if ((unsigned char)*repl == CTLESC && repl[1]) |
6868 | repl++; | 6876 | repl++; |
6869 | repl++; | 6877 | repl++; |