summaryrefslogtreecommitdiff
path: root/src/fe-text/term-terminfo.c
diff options
context:
space:
mode:
authorNei <ailin.nemui@gmail.com>2017-01-02 17:00:44 +0000
committerNei <ailin.nemui@gmail.com>2017-01-02 17:00:44 +0000
commit24d2d039b5bed6e42727784a15e67094dde69b1c (patch)
treef8400f550de2fcb73c97cd221f128b3134ee5c6e /src/fe-text/term-terminfo.c
parent7daa7a6aa95fc80bc82b5de60d11d03483289400 (diff)
parent8007e9e61d67044a6b29a266300a936e4c86fdd9 (diff)
downloadirssi-24d2d039b5bed6e42727784a15e67094dde69b1c.zip
Merge branch '3-out-of-bounds-read-with-invalid-utf8-in-term_addstr' into 'security'
Fix oob read on invalid utf8 in term_addstr See merge request !2
Diffstat (limited to 'src/fe-text/term-terminfo.c')
-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;