aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-11-17 20:27:18 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-11-17 20:27:18 +0100
commit08a5dab181fa4c28b7636c35021308e1e12e7b59 (patch)
treeb01e2c20104e75df48bcf02f4eea6746cda60e4e /shell
parent1a1143907c84308781e23f07d0c6c597bfd13abb (diff)
downloadbusybox-08a5dab181fa4c28b7636c35021308e1e12e7b59.tar.gz
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.c10
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,
len = number(loc);
}
}
- if (pos >= orig_len) {
+ if (pos < 0) {
+ /* ${VAR:$((-n)):l} starts n chars from the end */
+ pos = orig_len + pos;
+ }
+ if ((unsigned)pos >= orig_len) {
+ /* apart from obvious ${VAR:999999:l},
+ * covers ${VAR:$((-9999999)):l} - result is ""
+ * (bash-compat)
+ */
pos = 0;
len = 0;
}