aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorJarno Mäkipää <jmakip87@gmail.com>2019-10-10 00:06:03 +0300
committerRob Landley <rob@landley.net>2019-10-09 21:18:30 -0500
commit52422388520e4bf82e56a4cce3f2c2076cbed834 (patch)
tree79e2b18852aa5148f1df63c908763a3910d1a2b4 /toys/posix
parent8440d9b29fa8faed432bb20ec031bb5e72f0bea9 (diff)
downloadtoybox-52422388520e4bf82e56a4cce3f2c2076cbed834.tar.gz
ls: fix seqfault on broken locale
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
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/ls.c4
1 files changed, 2 insertions, 2 deletions
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;