From 52422388520e4bf82e56a4cce3f2c2076cbed834 Mon Sep 17 00:00:00 2001 From: Jarno Mäkipää Date: Thu, 10 Oct 2019 00:06:03 +0300 Subject: ls: fix seqfault on broken locale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When user builds toybox CFG_TOYBOX_I18N disabled and tries to list folder contents with multibyte characters other than UTF-8 ls might seqfault since wcrtomb returns -1 while locale set to fi_FI-UTF-8 disable CFG_TOYBOX_I18N touch őőőőaaőő ls --- toys/posix/ls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toys/posix') diff --git a/toys/posix/ls.c b/toys/posix/ls.c index 1640ea70..0956902f 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -66,14 +66,14 @@ GLOBALS( // Callback from crunch_str to represent unprintable chars static int crunch_qb(FILE *out, int cols, int wc) { - unsigned len = 1; + int len = 1; char buf[32]; if (FLAG(q)) *buf = '?'; else { if (wc<256) *buf = wc; // scrute the inscrutable, eff the ineffable, print the unprintable - else len = wcrtomb(buf, wc, 0); + else if ((len = wcrtomb(buf, wc, 0) ) == -1) len = 1; if (FLAG(b)) { char *to = buf, *from = buf+24; int i, j; -- cgit v1.2.3