diff options
author | 2016-03-18 11:29:19 +0000 | |
---|---|---|
committer | 2016-03-22 18:20:04 -0400 | |
commit | 856af4e3dc2406df7a2baed8058188acca9dbde6 (patch) | |
tree | 5f370dcd1b15a396ba695ec882fa4c26d59b145e /shell | |
parent | 4194c2875310c13ee3ca2bb0e1aea6a2ae67c55a (diff) | |
download | busybox-856af4e3dc2406df7a2baed8058188acca9dbde6.tar.gz busybox-856af4e3dc2406df7a2baed8058188acca9dbde6.tar.bz2 |
ash: fix corruption of ${#var} if $var contains UTF-8 characters
As reported in bug 8506:
$ X=abcdÉfghÍjklmnÓpqrstÚvwcyz
$ echo ${#X}
abcd26
The result should be 26.
This regression was introduced by:
<d68d1fb> 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 <martijn@inlv.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 3e3bfb896e0dd8a54caad9c6264e2452566b4012)
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 2 | ||||
-rw-r--r-- | shell/ash_test/ash-vars/var-utf8-length.right | 1 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/var-utf8-length.tests | 2 |
3 files changed, 5 insertions, 0 deletions
diff --git a/shell/ash.c b/shell/ash.c index 256e933e3..96aa2a223 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -6693,6 +6693,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} |