relates to issue reported in
https://github.com/landley/toybox/issues/146

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


-Jarno

---
 toys/posix/ls.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
From 4bacf2de7264c293cf506efa310f1f34f7df4707 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jarno=20M=C3=A4kip=C3=A4=C3=A4?= <jmaki...@gmail.com>
Date: Thu, 10 Oct 2019 00:06:03 +0300
Subject: [PATCH] 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(-)

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;
-- 
2.19.1

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to