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 3f3e2f4bc..b95356034 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -6740,7 +6740,15 @@ subevalvar(char *p, char *varname, int strloc, int subtype, | |||
6740 | len = number(loc); | 6740 | len = number(loc); |
6741 | } | 6741 | } |
6742 | } | 6742 | } |
6743 | if (pos >= orig_len) { | 6743 | if (pos < 0) { |
6744 | /* ${VAR:$((-n)):l} starts n chars from the end */ | ||
6745 | pos = orig_len + pos; | ||
6746 | } | ||
6747 | if ((unsigned)pos >= orig_len) { | ||
6748 | /* apart from obvious ${VAR:999999:l}, | ||
6749 | * covers ${VAR:$((-9999999)):l} - result is "" | ||
6750 | * (bash-compat) | ||
6751 | */ | ||
6744 | pos = 0; | 6752 | pos = 0; |
6745 | len = 0; | 6753 | len = 0; |
6746 | } | 6754 | } |