]> git.proxmox.com Git - vncterm.git/commitdiff
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 baaa3797bed8cc3cea73026c7ead66e895942f87..3ca00ba17bb6c3c5999ab45ffa1769db2c1f8f07 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) {
-             tc = vt->utf_char;
+               if (vt->utf_char <= USHRT_MAX) {
+                 tc = vt->utf_char;
+               } else {
+                 tc = 0;
+               }
            } else {
              continue;
            }