[PATCH] Fix runaway crash on closing xterm

Pavel Roskin proski at gnu.org
Fri Feb 5 00:27:35 UTC 2010


If minicom is run in xterm and the xterm window is closed, minicom 2.4
stays in memory for a while and then crashes.

wxgetch() mishandles the case when nfound is 0.  It would return mem[-1]
instead of some indicator that no more data is available.  To make
things worse, leftmem would become -1, and subsequent calls to wxgetch()
would result in leftmem being decremented further, making wxgetch()
return mem[-2], mem[-3] and so on until a segmentation fault happens.

This patch implements EOF handling from wxgetch() all the way up to
main().  Getting EOF would now make minicom exit silently.

Signed-off-by: Pavel Roskin <proski at gnu.org>
---
 src/main.c    |    3 +++
 src/minicom.c |    3 +++
 src/wkeys.c   |    4 ++--
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/main.c b/src/main.c
index e3f6e45..c651517 100644
--- a/src/main.c
+++ b/src/main.c
@@ -731,6 +731,9 @@ dirty_goto:
     if ((x & 2) == 2) {
       /* See which key was pressed. */
       c = keyboard(KGETKEY, 0);
+      if (c == EOF)
+        return EOF;
+
       if (c < 0) /* XXX - shouldn't happen */
         c += 256;
 
diff --git a/src/minicom.c b/src/minicom.c
index 2960112..61cc2d7 100644
--- a/src/minicom.c
+++ b/src/minicom.c
@@ -1527,6 +1527,9 @@ dirty_goto:
       case 'y': /* Paste file */
 	paste_file();
 	break;
+      case EOF: /* Cannot read from stdin anymore, exit silently */
+        quit = NORESET;
+        break;
       default:
         break;
     }
diff --git a/src/wkeys.c b/src/wkeys.c
index 208842d..06571c6 100644
--- a/src/wkeys.c
+++ b/src/wkeys.c
@@ -162,7 +162,7 @@ int wxgetch(void)
   }
 
   /* Some sequence still in memory ? */
-  if (leftmem) {
+  if (leftmem > 0) {
     leftmem--;
     if (leftmem == 0)
       pendingkeys = 0;
@@ -197,7 +197,7 @@ int wxgetch(void)
 #endif
 
     if (nfound < 1)
-      break;
+      return EOF;
 
     if (len == 1) {
       /* Enter and erase have precedence over anything else */



More information about the minicom-devel mailing list