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>
This commit is contained in:
Ron Yorston 2016-03-18 11:29:19 +00:00 committed by Mike Frysinger
parent 6701e91d84
commit 3e3bfb896e
3 changed files with 5 additions and 0 deletions

View File

@ -6692,6 +6692,8 @@ varvalue(char *name, int varflags, int flags, struct strlist *var_str_list)
if (subtype == VSLENGTH && len > 0) { if (subtype == VSLENGTH && len > 0) {
reinit_unicode_for_ash(); reinit_unicode_for_ash();
if (unicode_status == UNICODE_ON) { if (unicode_status == UNICODE_ON) {
STADJUST(-len, expdest);
discard = 0;
len = unicode_strlen(p); len = unicode_strlen(p);
} }
} }

View File

@ -0,0 +1 @@
26

View File

@ -0,0 +1,2 @@
X=abcdÉfghÍjklmnÓpqrstÚvwcyz
echo ${#X}