NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/47858: libedit widechar version mishandles EOF



>Number:         47858
>Category:       lib
>Synopsis:       libedit widechar version mishandles EOF
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun May 26 21:10:00 +0000 2013
>Originator:     Linas Vepstas
>Release:        libedit
>Organization:
>Environment:
>Description:
libedit, when built with widechar support (UTF-8/unicode), will spin in 
infinite loop in el_wgets() when getting an EOF. 

To reproduce, cat a file to a program using el_wgets().  At the end, the 
program will spin up to 100% CPU, stuck in a read-loop.

Bug is easy to find: in src/lib/libedit/src/read.c lines 323 to 347 there is a 
failure to check for EOF (num_read==0) and as a result, the thing spins.  Patch 
below.

--- libedit/src/read.c.orig   2013-05-26 15:55:23.000000000 -0500
+++ libedit/src/read.c  2013-05-26 16:04:52.000000000 -0500
@@ -341,6 +341,13 @@
      }
   }

+  /* Test for EOF */
+  if (num_read == 0) {
+     errno = 0;
+     *cp = '\0';
+     return 0;
+  }
+
 #ifdef WIDECHAR
   if (el->el_flags & CHARSET_IS_UTF8) {
      if (!utf8_islead((unsigned char)cbuf[0]))

>How-To-Repeat:

>Fix:
See patch provided above.




Home | Main Index | Thread Index | Old Index