From b285dd9b68811a71e6ebd49f20883340636301cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken=20Pettit=20=E2=80=8E?= Date: Wed, 16 Jan 2019 18:22:16 -0600 Subject: [PATCH] Perform a bounds check to fix a random Termcurses crash that I haven't been able to track down. The result of of the subtraction for priv->keycount should never be negative, but I think sometimes it is, so better to catch it and avoid a crash until I can track it down. --- system/termcurses/Kconfig | 2 ++ system/termcurses/tcurses_vt100.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/system/termcurses/Kconfig b/system/termcurses/Kconfig index 47732e160..8d67591e8 100644 --- a/system/termcurses/Kconfig +++ b/system/termcurses/Kconfig @@ -12,6 +12,8 @@ config SYSTEM_TERMCURSES Terminal emulation library for curses support on TTY type consoles such as serial port, CDCACM, telnet, etc. + Must deselect CONFIG_DISABLE_POLL! + config SYSTEM_TERMCURSES_VT100 bool "Terminal pdcurses support for VT-100" depends on SYSTEM_TERMCURSES diff --git a/system/termcurses/tcurses_vt100.c b/system/termcurses/tcurses_vt100.c index b66f1a440..f77503c7c 100644 --- a/system/termcurses/tcurses_vt100.c +++ b/system/termcurses/tcurses_vt100.c @@ -1041,6 +1041,13 @@ static int tcurses_vt100_getkeycode(FAR struct termcurses_s *dev, FAR int *speci /* Update keycount and keybuf */ priv->keycount -= x; + if (priv->keycount < 0) + { + /* Hmm, some bug. Better to simply ignore than to crash */ + + priv->keycount = 0; + } + if (priv->keycount != 0) { memmove(priv->keybuf, &priv->keybuf[x], priv->keycount);