Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Nov 2006 13:58:56 +0300
From:      Alex Povolotsky <tarkhil@webmail.sub.ru>
To:        freebsd-ports@freebsd.org
Subject:   Error in libunp, readline returns incorrect number of bytes on EOF
Message-ID:  <45618A70.5030701@webmail.sub.ru>

next in thread | raw e-mail | index | archive | help
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.






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45618A70.5030701>