]> git.proxmox.com Git - vncterm.git/commitdiff
fix bound checking on cursor move
authorDominik Csapak <d.csapak@proxmox.com>
Fri, 5 May 2017 12:19:06 +0000 (14:19 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 6 May 2017 06:07:08 +0000 (08:07 +0200)
changing most of the vt struct fields to unsigned, to avoid undefined
behaviour and use gotoxy for moving the cursor to correctly bound check
the cursor position

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

index 3ca00ba17bb6c3c5999ab45ffa1769db2c1f8f07..70fccef76db8bd1dc2b149d5c48b64a9ac490571 100644 (file)
--- a/vncterm.c
+++ b/vncterm.c
@@ -1405,10 +1405,7 @@ vncterm_putchar (vncTerm *vt, unicode ch)
       if (vt->esc_buf[0] == 0) {
        vt->esc_buf[0] = 1;
       }
-      vt->cy -= vt->esc_buf[0];
-      if (vt->cy < 0) {
-       vt->cy = 0;
-      }
+      vncterm_gotoxy (vt, vt->cx, vt->cy - vt->esc_buf[0]);
       break;
     case 'B':
     case 'e':
@@ -1416,10 +1413,7 @@ vncterm_putchar (vncTerm *vt, unicode ch)
       if (vt->esc_buf[0] == 0) {
        vt->esc_buf[0] = 1;
       }
-      vt->cy += vt->esc_buf[0];
-      if (vt->cy >= vt->height) {
-       vt->cy = vt->height - 1;
-      }
+      vncterm_gotoxy (vt, vt->cx, vt->cy + vt->esc_buf[0]);
       break;
     case 'C':
     case 'a':
@@ -1427,20 +1421,14 @@ vncterm_putchar (vncTerm *vt, unicode ch)
       if (vt->esc_buf[0] == 0) {
        vt->esc_buf[0] = 1;
       }
-      vt->cx += vt->esc_buf[0];
-      if (vt->cx >= vt->width) {
-       vt->cx = vt->width - 1;
-      }
+      vncterm_gotoxy (vt, vt->cx + vt->esc_buf[0], vt->cy);
       break;
     case 'D':
       /* move cursor left */
       if (vt->esc_buf[0] == 0) {
        vt->esc_buf[0] = 1;
       }
-      vt->cx -= vt->esc_buf[0];
-      if (vt->cx < 0) {
-       vt->cx = 0;
-      }
+      vncterm_gotoxy (vt, vt->cx - vt->esc_buf[0], vt->cy);
       break;
     case 'G':
     case '`':
index ffb5f2129c6676a638ee4215e62c6f21f8b0823c..8f7d8375f5489abccb9491e3424004ab6ce9b8b2 100644 (file)
--- a/vncterm.h
+++ b/vncterm.h
@@ -48,19 +48,19 @@ typedef struct vncTerm {
   // cursor
   TextAttributes cur_attrib;
   TextAttributes cur_attrib_saved;
-  int tty_state; // 0 - normal, 1 - ESC, 2 - CSI
+  unsigned int tty_state; // 0 - normal, 1 - ESC, 2 - CSI
   int cx; // cursor x position
   int cy; // cursor y position
   int cx_saved; // saved cursor x position
   int cy_saved; // saved cursor y position
-  int esc_buf[MAX_ESC_PARAMS];
-  int esc_count;
-  int esc_ques;
-  int esc_has_par;
+  unsigned int esc_buf[MAX_ESC_PARAMS];
+  unsigned int esc_count;
+  unsigned int esc_ques;
+  unsigned int esc_has_par;
   char osc_textbuf[4096];
   char osc_cmd;
-  int region_top;
-  int region_bottom;
+  unsigned int region_top;
+  unsigned int region_bottom;
 
   unsigned int charset:1; // G0 or G1
   unsigned int charset_saved:1; // G0 or G1