From 3e3bfb896e0dd8a54caad9c6264e2452566b4012 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 18 Mar 2016 11:29:19 +0000 Subject: ash: fix corruption of ${#var} if $var contains UTF-8 characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As reported in bug 8506: $ X=abcdÉfghÍjklmnÓpqrstÚvwcyz $ echo ${#X} abcd26 The result should be 26. This regression was introduced by: 2015-05-18 [Ron Yorston] ash: code shrink around varvalue The length in characters was being used to discard the contents of the variable instead of the length in bytes. URL: https://bugs.busybox.net/8506 Reported-by: Martijn Dekker Signed-off-by: Ron Yorston Signed-off-by: Mike Frysinger --- shell/ash.c | 2 ++ shell/ash_test/ash-vars/var-utf8-length.right | 1 + shell/ash_test/ash-vars/var-utf8-length.tests | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 shell/ash_test/ash-vars/var-utf8-length.right create mode 100755 shell/ash_test/ash-vars/var-utf8-length.tests (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index b5a2d961d..5613e1f33 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -6692,6 +6692,8 @@ varvalue(char *name, int varflags, int flags, struct strlist *var_str_list) if (subtype == VSLENGTH && len > 0) { reinit_unicode_for_ash(); if (unicode_status == UNICODE_ON) { + STADJUST(-len, expdest); + discard = 0; len = unicode_strlen(p); } } diff --git a/shell/ash_test/ash-vars/var-utf8-length.right b/shell/ash_test/ash-vars/var-utf8-length.right new file mode 100644 index 000000000..6f4247a62 --- /dev/null +++ b/shell/ash_test/ash-vars/var-utf8-length.right @@ -0,0 +1 @@ +26 diff --git a/shell/ash_test/ash-vars/var-utf8-length.tests b/shell/ash_test/ash-vars/var-utf8-length.tests new file mode 100755 index 000000000..d04b2cbb6 --- /dev/null +++ b/shell/ash_test/ash-vars/var-utf8-length.tests @@ -0,0 +1,2 @@ +X=abcdÉfghÍjklmnÓpqrstÚvwcyz +echo ${#X} -- cgit v1.2.3-55-g6feb From 787972f60b08c34059de65f9ee24febaa50667a2 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 22 Mar 2016 18:15:14 -0400 Subject: ash_test: printenv: fix missing includes Signed-off-by: Mike Frysinger --- shell/ash_test/printenv.c | 1 + 1 file changed, 1 insertion(+) (limited to 'shell') diff --git a/shell/ash_test/printenv.c b/shell/ash_test/printenv.c index c4ccda8a6..c0c5e197c 100644 --- a/shell/ash_test/printenv.c +++ b/shell/ash_test/printenv.c @@ -24,6 +24,7 @@ with Bash; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ +#include #include #include -- cgit v1.2.3-55-g6feb From b9b7aa1910907f59f1130667fbe7b870087e97f8 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 22 Mar 2016 18:15:24 -0400 Subject: ash_test: ignore generated files Signed-off-by: Mike Frysinger --- shell/ash_test/.gitignore | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 shell/ash_test/.gitignore (limited to 'shell') diff --git a/shell/ash_test/.gitignore b/shell/ash_test/.gitignore new file mode 100644 index 000000000..a1f937cdd --- /dev/null +++ b/shell/ash_test/.gitignore @@ -0,0 +1,7 @@ +/ash +/printenv +/recho +/zecho + +/*.fail +*.xx -- cgit v1.2.3-55-g6feb