summaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko2010-05-21 15:24:12 +0200
committerDenys Vlasenko2010-05-21 15:24:12 +0200
commit73e013fca7afd2edc9ba8530df77c8210a14700b (patch)
treecee35b3493f12565fd20100be1ea2da4a6a86baf /shell/hush.c
parenta88585a931c7e81d4d3d393127d8ad8c0fe73fb5 (diff)
downloadbusybox-73e013fca7afd2edc9ba8530df77c8210a14700b.zip
busybox-73e013fca7afd2edc9ba8530df77c8210a14700b.tar.gz
hush: handle ${var:NUM:} too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 945077d..6cf8899 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2649,12 +2649,17 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char
beg = bb_strtou(exp_word, &end, 0);
//bb_error_msg("beg:'%s'=%u end:'%s'", exp_word, beg, end);
if (*end == ':') {
- len = bb_strtou(end + 1, &end, 0);
+ if (end[1] != '\0') /* not ${var:NUM:} */
+ len = bb_strtou(end + 1, &end, 0);
+ else {
+ len = 0;
+ end++;
+ }
//bb_error_msg("len:%u end:'%s'", len, end);
}
if (*end == '\0') {
//bb_error_msg("from val:'%s'", val);
- if (!val || beg >= strlen(val))
+ if (len == 0 || !val || beg >= strlen(val))
val = "";
else
val = dyn_val = xstrndup(val + beg, len);
@@ -2663,6 +2668,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char
#endif
{
die_if_script("malformed ${%s...}", var);
+ val = "";
}
} else { /* one of "-=+?" */
/* Standard-mandated substitution ops: