diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-11-17 20:27:18 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-11-17 20:27:18 +0100 |
commit | 08a5dab181fa4c28b7636c35021308e1e12e7b59 (patch) | |
tree | b01e2c20104e75df48bcf02f4eea6746cda60e4e /shell | |
parent | 1a1143907c84308781e23f07d0c6c597bfd13abb (diff) | |
download | busybox-w32-08a5dab181fa4c28b7636c35021308e1e12e7b59.tar.gz busybox-w32-08a5dab181fa4c28b7636c35021308e1e12e7b59.tar.bz2 busybox-w32-08a5dab181fa4c28b7636c35021308e1e12e7b59.zip |
ash: fix handling of negative start value in ${v:start:len}
function old new delta
subevalvar 1140 1168 +28
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-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 705fe9fa4..90fb00fbd 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -6411,7 +6411,15 @@ subevalvar(char *p, char *varname, int strloc, int subtype, | |||
6411 | len = number(loc); | 6411 | len = number(loc); |
6412 | } | 6412 | } |
6413 | } | 6413 | } |
6414 | if (pos >= orig_len) { | 6414 | if (pos < 0) { |
6415 | /* ${VAR:$((-n)):l} starts n chars from the end */ | ||
6416 | pos = orig_len + pos; | ||
6417 | } | ||
6418 | if ((unsigned)pos >= orig_len) { | ||
6419 | /* apart from obvious ${VAR:999999:l}, | ||
6420 | * covers ${VAR:$((-9999999)):l} - result is "" | ||
6421 | * (bash-compat) | ||
6422 | */ | ||
6415 | pos = 0; | 6423 | pos = 0; |
6416 | len = 0; | 6424 | len = 0; |
6417 | } | 6425 | } |