bound check utf8 characters
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 28 Feb 2017 11:06:43 +0000 (12:06 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 9 Mar 2017 09:10:28 +0000 (10:10 +0100)
since we load the fontmap from psf1 font files, we only have characters
for a maximum codepoint of 0xFFFF, so we save the char in an
unsigned short (16bit) but we decode up to 6 bytes of utf8
so we have to correctly bound check the assignment, else we can get
garbled characters on the terminal

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
vncterm.c

index baaa379..3ca00ba 100644 (file)
--- a/vncterm.c
+++ b/vncterm.c
@@ -1790,7 +1790,11 @@ vncterm_puts (vncTerm *vt, const char *buf, int len)
            vt->utf_char = (vt->utf_char << 6) | (c & 0x3f);
            vt->utf_count--;
            if (vt->utf_count == 0) {
            vt->utf_char = (vt->utf_char << 6) | (c & 0x3f);
            vt->utf_count--;
            if (vt->utf_count == 0) {
-             tc = vt->utf_char;
+               if (vt->utf_char <= USHRT_MAX) {
+                 tc = vt->utf_char;
+               } else {
+                 tc = 0;
+               }
            } else {
              continue;
            }
            } else {
              continue;
            }