summaryrefslogtreecommitdiff
path: root/src/fe-text
diff options
context:
space:
mode:
authorJoseph Bisch <joseph.bisch@gmail.com>2016-12-19 09:31:38 -0500
committerJoseph Bisch <joseph.bisch@gmail.com>2016-12-19 15:52:05 -0500
commit8007e9e61d67044a6b29a266300a936e4c86fdd9 (patch)
treea36d520f75d1cf33e76684c2c6000fb42783213c /src/fe-text
parent1c6695107c09e8861a696d66b029e7df62589fcd (diff)
downloadirssi-8007e9e61d67044a6b29a266300a936e4c86fdd9.zip
Fix oob read on invalid utf8 in term_addstr
Diffstat (limited to 'src/fe-text')
-rw-r--r--src/fe-text/term-terminfo.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c
index b2478c62..3098a4e4 100644
--- a/src/fe-text/term-terminfo.c
+++ b/src/fe-text/term-terminfo.c
@@ -539,9 +539,16 @@ int term_addstr(TERM_WINDOW *window, const char *str)
if (term_type == TERM_TYPE_UTF8) {
while (*ptr != '\0') {
- tmp = g_utf8_get_char(ptr);
- len += unichar_isprint(tmp) ? mk_wcwidth(tmp) : 1;
- ptr = g_utf8_next_char(ptr);
+ tmp = g_utf8_get_char_validated(ptr, -1);
+ /* On utf8 error, treat as single byte and try to
+ continue interpretting rest of string as utf8 */
+ if (tmp == (gunichar)-1 || tmp == (gunichar)-2) {
+ len++;
+ ptr++;
+ } else {
+ len += unichar_isprint(tmp) ? mk_wcwidth(tmp) : 1;
+ ptr = g_utf8_next_char(ptr);
+ }
}
} else
len = raw_len;