NetBSD-Bugs archive

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

Re: lib/47858: libedit widechar version mishandles EOF



The following reply was made to PR lib/47858; it has been noted by GNATS.

From: Linas Vepstas <linasvepstas%gmail.com@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: lib/47858: libedit widechar version mishandles EOF
Date: Sun, 26 May 2013 16:25:19 -0500

 Just to be clear, here is a closer description of the problem.  The
 offending lines are these:
 
 #ifdef WIDECHAR
    if (el->el_flags & CHARSET_IS_UTF8) {
       if (!utf8_islead((unsigned char)cbuf[0]))
          goto again; /* discard the byte we read and try again */
 
 When an EOF is read, cbuf[0] contains some sort of undefined garbage,
 left over from a previous read, thus the goto again is taken.  The
 non-widechar version doesn't have this problem, and thus perhaps my
 earlier patch is too general/too broad.  I believe it's a great patch,
 but if you don't like it, the below is a more conservative patch:
 
 --- libedit/src/read.c.orig   2013-05-26 15:55:23.000000000 -0500
 +++ libedit/src/read.c  2013-05-26 16:23:45.000000000 -0500
 @@ -342,6 +342,13 @@
    }
 
  #ifdef WIDECHAR
 +  /* Test for EOF; cbuf[0] holds garbage when num_read == 0 */
 +  if (num_read == 0) {
 +     errno = 0;
 +     *cp = '\0';
 +     return 0;
 +  }
 +
    if (el->el_flags & CHARSET_IS_UTF8) {
       if (!utf8_islead((unsigned char)cbuf[0]))
          goto again; /* discard the byte we read and try again */
 



Home | Main Index | Thread Index | Old Index