mirror of
https://github.com/irssi/irssi.git
synced 2025-04-26 04:51:11 -05:00
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
This commit is contained in:
commit
24d2d039b5
@ -539,10 +539,17 @@ int term_addstr(TERM_WINDOW *window, const char *str)
|
|||||||
|
|
||||||
if (term_type == TERM_TYPE_UTF8) {
|
if (term_type == TERM_TYPE_UTF8) {
|
||||||
while (*ptr != '\0') {
|
while (*ptr != '\0') {
|
||||||
tmp = g_utf8_get_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;
|
len += unichar_isprint(tmp) ? mk_wcwidth(tmp) : 1;
|
||||||
ptr = g_utf8_next_char(ptr);
|
ptr = g_utf8_next_char(ptr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
len = raw_len;
|
len = raw_len;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user