dovecot-2.2: i_stream_read_next_line() now sets stream_errno=ENO...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jan 14 08:01:59 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/20a545f932e3
changeset: 15640:20a545f932e3
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jan 14 07:57:39 2013 +0200
description:
i_stream_read_next_line() now sets stream_errno=ENOBUFS if input buffer gets full.
Previously the caller couldn't easily separate this condition from "more
data needed", potentially causing infinite loops.

diffstat:

 src/lib/istream.c |  9 ++++++++-
 src/lib/istream.h |  3 ++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diffs (33 lines):

diff -r 6654ed22af78 -r 20a545f932e3 src/lib/istream.c
--- a/src/lib/istream.c	Sun Jan 13 19:15:37 2013 +0200
+++ b/src/lib/istream.c	Mon Jan 14 07:57:39 2013 +0200
@@ -387,8 +387,15 @@
 		if (line != NULL)
 			break;
 
-		if (i_stream_read(stream) <= 0)
+		switch (i_stream_read(stream)) {
+		case -2:
+			stream->stream_errno = ENOBUFS;
+			return NULL;
+		case -1:
 			return i_stream_last_line(stream->real_stream);
+		case 0:
+			return NULL;
+		}
 	}
 	return line;
 }
diff -r 6654ed22af78 -r 20a545f932e3 src/lib/istream.h
--- a/src/lib/istream.h	Sun Jan 13 19:15:37 2013 +0200
+++ b/src/lib/istream.h	Mon Jan 14 07:57:39 2013 +0200
@@ -123,7 +123,8 @@
    if the last line should be returned if it doesn't end with LF. */
 char *i_stream_next_line(struct istream *stream);
 /* Like i_stream_next_line(), but reads for more data if needed. Returns NULL
-   if more data is needed or error occurred. */
+   if more data is needed or error occurred. If the input buffer gets full,
+   stream_errno is set to ENOBUFS. */
 char *i_stream_read_next_line(struct istream *stream);
 /* Returns TRUE if the last line read with i_stream_next_line() ended with
    CRLF (instead of LF). */


More information about the dovecot-cvs mailing list