Be more strict about invalid UTF-8.

This commit is contained in:
nicm
2015-11-14 10:56:31 +00:00
parent c56b81a2ce
commit 64333e3ef8
6 changed files with 76 additions and 54 deletions

13
input.c
View File

@ -446,11 +446,11 @@ const struct input_transition input_state_ground_table[] = {
{ 0x1c, 0x1f, input_c0_dispatch, NULL },
{ 0x20, 0x7e, input_print, NULL },
{ 0x7f, 0x7f, NULL, NULL },
{ 0x80, 0xc1, input_print, NULL },
{ 0x80, 0xc1, NULL, NULL },
{ 0xc2, 0xdf, input_utf8_open, &input_state_utf8_one },
{ 0xe0, 0xef, input_utf8_open, &input_state_utf8_two },
{ 0xf0, 0xf4, input_utf8_open, &input_state_utf8_three },
{ 0xf5, 0xff, input_print, NULL },
{ 0xf5, 0xff, NULL, NULL },
{ -1, -1, NULL, NULL }
};
@ -1923,7 +1923,8 @@ input_utf8_open(struct input_ctx *ictx)
{
struct utf8_data *ud = &ictx->utf8data;
utf8_open(ud, ictx->ch);
if (!utf8_open(ud, ictx->ch))
log_fatalx("UTF-8 open invalid %#hhx", ictx->ch);
log_debug("%s %hhu", __func__, ud->size);
@ -1936,7 +1937,8 @@ input_utf8_add(struct input_ctx *ictx)
{
struct utf8_data *ud = &ictx->utf8data;
utf8_append(ud, ictx->ch);
if (utf8_append(ud, ictx->ch) != 1)
log_fatalx("UTF-8 add invalid %#hhx", ictx->ch);
log_debug("%s", __func__);
@ -1949,7 +1951,8 @@ input_utf8_close(struct input_ctx *ictx)
{
struct utf8_data *ud = &ictx->utf8data;
utf8_append(ud, ictx->ch);
if (utf8_append(ud, ictx->ch) != 0)
log_fatalx("UTF-8 close invalid %#hhx", ictx->ch);
log_debug("%s %hhu '%*s' (width %hhu)", __func__, ud->size,
(int)ud->size, ud->data, ud->width);