[git commit] hush: fix fallout from tweaking ${var:START:LEN} code

Denys Vlasenko vda.linux at googlemail.com
Wed Dec 23 11:38:03 UTC 2020


commit: https://git.busybox.net/busybox/commit/?id=a7b52d26c435c35336ddc5ff93d5680e648345c8
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
expand_one_var                                      2344    2353      +9

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/hush.c                                            | 2 +-
 shell/hush_test/hush-vars/var_bash_repl_empty_var.right | 1 +
 shell/hush_test/hush-vars/var_bash_repl_empty_var.tests | 2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/shell/hush.c b/shell/hush.c
index 6b8f1c88c..9403e1f6c 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -6617,7 +6617,7 @@ static NOINLINE int expand_one_var(o_string *output, int n,
 			exp_word = p;
 			p = strchr(p, SPECIAL_VAR_SYMBOL);
 			*p = '\0';
-			vallen = strlen(val);
+			vallen = val ? strlen(val) : 0;
 			if (beg < 0) {
 				/* negative beg counts from the end */
 				beg = (arith_t)vallen + beg;
diff --git a/shell/hush_test/hush-vars/var_bash_repl_empty_var.right b/shell/hush_test/hush-vars/var_bash_repl_empty_var.right
index 892916783..a8d1a3bef 100644
--- a/shell/hush_test/hush-vars/var_bash_repl_empty_var.right
+++ b/shell/hush_test/hush-vars/var_bash_repl_empty_var.right
@@ -1,2 +1,3 @@
 
+w
 Ok:0
diff --git a/shell/hush_test/hush-vars/var_bash_repl_empty_var.tests b/shell/hush_test/hush-vars/var_bash_repl_empty_var.tests
index 73a43d38e..22aaba560 100755
--- a/shell/hush_test/hush-vars/var_bash_repl_empty_var.tests
+++ b/shell/hush_test/hush-vars/var_bash_repl_empty_var.tests
@@ -1,3 +1,5 @@
+unset v
+echo ${v/*/w}
 v=''
 echo ${v/*/w}
 echo Ok:$?


More information about the busybox-cvs mailing list