Error in libunp, readline returns incorrect number of bytes on EOF

Alex Povolotsky tarkhil at webmail.sub.ru
Mon Nov 20 02:59:25 PST 2006


Hello!

I've found that readline() in libunp returns incorrect number of bytes 
(one extra) when encounters EOF not preceeded by '\n';

Here is the patch I've made for it.

=== cut ===
--- lib/readline.c.orig Mon Nov 20 13:51:15 2006
+++ lib/readline.c      Mon Nov 20 13:51:41 2006
@@ -39,8 +39,10 @@
                } else if (rc == 0) {
                        if (n == 1)
                                return(0);      /* EOF, no data read */
-                       else
+                       else {
+                               n--; /* byte was NOT read */
                                break;          /* EOF, some data was 
read */
+                       }
                } else
                        return(-1);             /* error, errno set by 
read() */
        }
=== cut ===

It has been tested and runs OK.

Alex.





More information about the freebsd-ports mailing list