nntp_read_line bug?

Russ Allbery rra at stanford.edu
Fri Oct 24 18:52:52 UTC 2003


Forrest J Cavalier <mibsoft at epix.net> writes:

> So, what is the API designed to guarantee with respect to *line values
> obtained by previous calls to nntp_read_line()?  Aren't all those
> previously returned pointers considered stale after any call to a nntp_
> routine?

Yes.

> If that is true, then the buffer compacting should be done always when
> within 1024 bytes of the end of the buffer, right?

Yes.

Bug in nntp.c.  Thank you!  I'm committing a fix now.

--- nntp.c      2003/07/22 19:04:08     1.2
+++ nntp.c      2003/10/24 18:52:36
@@ -171,7 +171,10 @@ nntp_read_line(struct nntp *nntp, time_t
     size_t offset;
     size_t start = 0;
 
-    if (in->used + in->left == in->size)
+    /* Compact the buffer if there are fewer than 128 characters left; this
+       limit is chosen somewhat arbitrarily, but note that most NNTP lines
+       are fairly short. */
+    if (in->used + in->left + 128 >= in->size)
         buffer_compact(in);
     while (status == NNTP_READ_OK) {
         if (buffer_find_string(in, "\r\n", start, &offset)) {
@@ -186,6 +189,8 @@ nntp_read_line(struct nntp *nntp, time_t
            boundaries. */
         start = (in->left > 0) ? in->left - 1 : 0;
         status = nntp_read_data(nntp, timeout);
+        if (in->used + in->left + 128 >= in->size)
+            buffer_compact(in);
     }
     return status;
 }

-- 
Russ Allbery (rra at stanford.edu)             <http://www.eyrie.org/~eagle/>

    Please send questions to the list rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.


More information about the inn-workers mailing list