diff options
author | Sam Mendoza-Jonas <sam@mendozajonas.com> | 2016-03-03 13:31:18 +1100 |
---|---|---|
committer | Sam Mendoza-Jonas <sam@mendozajonas.com> | 2016-03-15 14:34:41 +1100 |
commit | 5c3c324cc42f179fb41ca825fbce06bc445c730b (patch) | |
tree | bfa7723daed73c8c82f0083ab108feb5df608c56 | |
parent | 0a10130b9d66a6f3f94094400871c9410b340674 (diff) | |
download | talos-petitboot-5c3c324cc42f179fb41ca825fbce06bc445c730b.tar.gz talos-petitboot-5c3c324cc42f179fb41ca825fbce06bc445c730b.zip |
lib/fold: Catch error case from mbrtowc()
The assert() statement in fold_text() only evaluates in a debug build.
If mbrtowc() encounters an error return the portion of the string that
has been parsed and stop.
This avoids an issue with glibc 2.22 where previous calls to
setlocale() failed and set an unsuitable locale. Since the error was not
caught this resulted in an infinite loop when trying to access the
Language screen.
Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
-rw-r--r-- | lib/fold/fold.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/fold/fold.c b/lib/fold/fold.c index 2566253..812a324 100644 --- a/lib/fold/fold.c +++ b/lib/fold/fold.c @@ -36,9 +36,10 @@ void fold_text(const char *text, assert(bytes != (size_t)-1); - /* we'll get a zero size for the nul terminator, or (size_t) -2 - * if we've reached the end of the buffer */ - if (!bytes || bytes == (size_t) -2) { + /* we'll get a zero size for the nul terminator, (size_t) -2 + * if we've reached the end of the buffer, or (size_t) -1 on + * error */ + if (!bytes || bytes == (size_t) -2 || bytes == (size_t) -1) { line_cb(arg, start, end - start); break; } |